Registry / http-networking / rollup-plugin-esm-import-to-url

rollup-plugin-esm-import-to-url

JSON →
library2.1.0jsnpmunverified

A Rollup plugin that transforms bare import specifiers (e.g., 'lit-element') into absolute URLs for ES module output. Suitable for CDN loading or micro-frontends. Current version 2.1.0. Release pattern is ad-hoc. Differentiators: integrates with Rollup's resolve pipeline, ensures bare imports are replaced only when mapped, and throws if specifiers are also listed in Rollup's external option.

npm install rollup-plugin-esm-import-to-url
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-ESM-
R
rollup-plugin-esm-import-to-url
http-networkingjavascriptv2.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import esmImportToUrl from 'rollup-plugin-esm-import-to-url'
const esmImportToUrl = require('rollup-plugin-esm-import-to-url')
Package exports a default export. CommonJS require would not work for v2+ as it's ESM-only.
esmImportToUrl
import esmImportToUrl from 'rollup-plugin-esm-import-to-url'
import { esmImportToUrl } from 'rollup-plugin-esm-import-to-url'
Default export, not named. Named import will result in undefined.
Rollup plugins array entry
esmImportToUrl({ imports: { 'pkg': 'https://cdn.example.com/pkg.js' } })
esmImportToUrl({ 'pkg': 'https://cdn.example.com/pkg.js' })
Options must be wrapped in object with `imports` key; incorrect to pass direct property mapping.

Configures Rollup to replace bare import 'lit-element' with a CDN URL in the ESM output bundle.

// rollup.config.js import esmImportToUrl from 'rollup-plugin-esm-import-to-url'; export default { input: 'src/main.js', plugins: [ esmImportToUrl({ imports: { 'lit-element': 'https://cdn.jsdelivr.net/npm/lit-element@2.4.0/lit-element.js', }, }), ], output: { file: 'dist/bundle.js', format: 'esm', }, };
Debug
Known issues
breakingIf a bare import specifier is also listed in Rollup's `external` option, the plugin will throw an error.
fix
Remove the specifier from `external` or ensure it is not duplicated.
affects: >=1.0.0
breakingOutput must be formatted as 'esm' (ES modules). Other formats like 'cjs' or 'iife' will cause incorrect behavior or errors.
fix
Set `output.format` to 'esm'.
affects: >=1.0.0
deprecatedRequires Node.js version >=10. Older versions may fail.
fix
Upgrade Node.js to v10 or later.
affects: >=2.0.0
gotchaPlugin only transforms bare import specifiers that are mapped in the `imports` option; other bare imports remain unchanged and may fail at runtime.
fix
Ensure all external bare imports are explicitly mapped.
affects: >=1.0.0
Errors
Common errors & fixes
Error: The following imports are both in the import map and in Rollup's external list: ["lit-element"]
Duplicate declaration: import specifier appears in both `external` and plugin's `imports`.
fix
Remove the specifier from Rollup's `external` option and rely on the plugin.
Error: [plugin:esm-import-to-url] Could not resolve import 'lit-element'
Bare import specifier is not mapped in `imports` option and not otherwise resolved.
fix
Add the specifier to `imports` in plugin options.
ReferenceError: require is not defined (when using CommonJS require)
Package is ESM-only; using `require()` in Node.js <13 or without ESM support fails.
fix
Use `import` syntax or ensure Node.js version supports ESM.
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies
rolluprequiredThis is a Rollup plugin; Rollup is a peer dependency.
Agent activity
4 hits · last 30 days
node
4
Resources
rollup-plugin-esm-import-to-url — npm install rollup-plugin-esm-import-to-url · libregistry