Registry / devops / rollup-plugin-external-globals

rollup-plugin-external-globals

JSON →
library0.13.0jsnpmunverified

A Rollup plugin that transforms external import statements (static and dynamic) into global variable references, similar to Rollup's built-in output.globals option but with broader support. Version 0.13.0 requires Rollup ^2.25.0 || ^3.3.0 || ^4.1.4. It uses a moduleId-to-variableName map (object or function) to rewrite imports to direct globals, helping in scenarios like bundling for browser environments where dependencies are loaded via script tags. Key differentiators: it works with dynamic imports, supports include/exclude patterns via picomatch, provides a custom dynamic wrapper, and can use const bindings via the constBindings option. It ships TypeScript types.

npm install rollup-plugin-external-globals
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-EXTE
R
rollup-plugin-external-globals
devopsjavascriptv0.13.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
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 18–223 runs
build_error
glibc
node 18–223 runs
build_error
Code
Verified usage

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

default
✓ import externalGlobals from 'rollup-plugin-external-globals'
✗ const externalGlobals = require('rollup-plugin-external-globals')
Esm-only; CommonJS require is not supported
createPlugin
✓ import { createPlugin } from 'rollup-plugin-external-globals'
Named export 'createPlugin' is available, but default export is the same function (these are equivalent)
Plugin
✓ import type { Plugin } from 'rollup-plugin-external-globals'
The package exports TypeScript types; import type for type declarations

Shows basic usage: map jquery import to global $ variable in a Rollup configuration.

import externalGlobals from 'rollup-plugin-external-globals'; export default { input: 'src/index.js', output: { dir: 'dist', format: 'es' }, plugins: [ externalGlobals({ jquery: '$' }) ] };
Debug
Known issues
breakingv0.12.0 changed variable declaration from `var` to `const`? Actually default is `var`, with `constBindings` option. Also throws on export all declaration.
fix
If you rely on variable hoisting, the default `var` might be fine; if you need `const`, set `constBindings: true`. Avoid `export * from` with external globals.
affects: >=0.12.0
breakingv0.9.0 bumped minimal Rollup version to 4.x.
fix
Update Rollup to version 4 or later.
affects: >=0.9.0
gotchaPlugin does not transform require() calls; only import/export statements.
fix
Place this plugin after rollup-plugin-commonjs or other CJS transformers.
affects: >=0.0.0
gotchaDynamic import transformed to `Promise.resolve(global)` – the resolved object is always a module namespace, but global variable might not be.
fix
Ensure the global variable returns the expected default or shape; consider setting `dynamicWrapper` to adjust.
affects: >=0.0.0
deprecatedv0.13.0 changed include/exclude signature (now uses picomatch).
fix
Update include/exclude patterns to picomatch syntax if you were using older patterns.
affects: >=0.13.0
Errors
Common errors & fixes
Error: [plugin external-globals] Could not resolve import 'jquery'
The plugin marks the module as external but Rollup cannot resolve it because the module is not installed or not listed in external.
fix
Add the module to `output.globals` or ensure it's listed in `external` options.
TypeError: Cannot read properties of undefined (reading 'default')
Dynamic import transformation returns a global variable that is not an object with a default property, and the code expects a module namespace with default.
fix
Set `dynamicWrapper` to a function that returns the global variable directly, e.g., `() => 'Promise.resolve({ default: myGlobal })'`.
Error: Unknown plugin hook: 'debug'
Using version >=0.12.1 but Rollup version is 2.x where debug hook is not available.
fix
Upgrade Rollup to 3.x or 4.x, or downgrade plugin to 0.12.0.
Upgrade
Version history
0.13.0latest on npm
Audit
Dependencies
rollupoptionalpeer dependency; plugin is designed to work with Rollup's build system
Agent activity
6 hits · last 30 days
node
4
Resources
rollup-plugin-external-globals — npm install rollup-plugin-external-globals · libregistry