{"id":22018,"library":"rollup-plugin-external-globals","title":"rollup-plugin-external-globals","description":"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.","status":"active","version":"0.13.0","language":"javascript","source_language":"en","source_url":"https://github.com/eight04/rollup-plugin-external-globals","tags":["javascript","rollup-plugin","es","transform","external","globals","typescript"],"install":[{"cmd":"npm install rollup-plugin-external-globals","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-external-globals","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-external-globals","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency; plugin is designed to work with Rollup's build system","package":"rollup","optional":true}],"imports":[{"note":"Esm-only; CommonJS require is not supported","wrong":"const externalGlobals = require('rollup-plugin-external-globals')","symbol":"default","correct":"import externalGlobals from 'rollup-plugin-external-globals'"},{"note":"Named export 'createPlugin' is available, but default export is the same function (these are equivalent)","wrong":"","symbol":"createPlugin","correct":"import { createPlugin } from 'rollup-plugin-external-globals'"},{"note":"The package exports TypeScript types; import type for type declarations","wrong":"","symbol":"Plugin","correct":"import type { Plugin } from 'rollup-plugin-external-globals'"}],"quickstart":{"code":"import externalGlobals from 'rollup-plugin-external-globals';\n\nexport default {\n  input: 'src/index.js',\n  output: {\n    dir: 'dist',\n    format: 'es'\n  },\n  plugins: [\n    externalGlobals({\n      jquery: '$'\n    })\n  ]\n};","lang":"javascript","description":"Shows basic usage: map jquery import to global $ variable in a Rollup configuration."},"warnings":[{"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.","message":"v0.12.0 changed variable declaration from `var` to `const`? Actually default is `var`, with `constBindings` option. Also throws on export all declaration.","severity":"breaking","affected_versions":">=0.12.0"},{"fix":"Update Rollup to version 4 or later.","message":"v0.9.0 bumped minimal Rollup version to 4.x.","severity":"breaking","affected_versions":">=0.9.0"},{"fix":"Place this plugin after rollup-plugin-commonjs or other CJS transformers.","message":"Plugin does not transform require() calls; only import/export statements.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Ensure the global variable returns the expected default or shape; consider setting `dynamicWrapper` to adjust.","message":"Dynamic import transformed to `Promise.resolve(global)` – the resolved object is always a module namespace, but global variable might not be.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Update include/exclude patterns to picomatch syntax if you were using older patterns.","message":"v0.13.0 changed include/exclude signature (now uses picomatch).","severity":"deprecated","affected_versions":">=0.13.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Add the module to `output.globals` or ensure it's listed in `external` options.","cause":"The plugin marks the module as external but Rollup cannot resolve it because the module is not installed or not listed in external.","error":"Error: [plugin external-globals] Could not resolve import 'jquery'"},{"fix":"Set `dynamicWrapper` to a function that returns the global variable directly, e.g., `() => 'Promise.resolve({ default: myGlobal })'`.","cause":"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.","error":"TypeError: Cannot read properties of undefined (reading 'default')"},{"fix":"Upgrade Rollup to 3.x or 4.x, or downgrade plugin to 0.12.0.","cause":"Using version >=0.12.1 but Rollup version is 2.x where debug hook is not available.","error":"Error: Unknown plugin hook: 'debug'","affected_versions":">=0.12.1"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}