{"id":22020,"library":"rollup-plugin-externals","title":"rollup-plugin-externals","description":"A Rollup plugin that mimics webpack's externals configuration, allowing you to mark dependencies as external and provide global variable names for bundling with script tags. Currently at v0.0.1, it is a lightweight alternative to @rollup/plugin-node-resolve combined with manual external handling. It maps module IDs to global variable names, emitting `module.exports = window.VariableName` stubs at build time. Suitable for library authors bundling for browser environments. No dependencies and ships TypeScript types.","status":"active","version":"0.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/magic-akari/rollup-plugin-externals","tags":["javascript","rollup-plugin","typescript"],"install":[{"cmd":"npm install rollup-plugin-externals","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-externals","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-externals","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package only exports a named function; there is no default export.","wrong":"import externals from 'rollup-plugin-externals'","symbol":"externals","correct":"import { externals } from 'rollup-plugin-externals'"},{"note":"CommonJS require must destructure; using it as a default will not work.","wrong":"const externals = require('rollup-plugin-externals')","symbol":"externals (require)","correct":"const { externals } = require('rollup-plugin-externals')"},{"note":"TypeScript users can import the type for options object.","wrong":"","symbol":"TypeScript type","correct":"import type { ExternalsOptions } from 'rollup-plugin-externals'"}],"quickstart":{"code":"import { defineConfig } from 'rollup';\nimport { externals } from 'rollup-plugin-externals';\n\nexport default defineConfig({\n  input: 'src/index.js',\n  output: {\n    dir: 'dist',\n    format: 'iife',\n  },\n  plugins: [\n    externals({\n      'react': 'React',\n      'react-dom': 'ReactDOM',\n    }),\n  ],\n});","lang":"typescript","description":"Demonstrates how to use the externals plugin in a Rollup config to map 'react' and 'react-dom' to global variables for IIFE output."},"warnings":[{"fix":"Use `output.format: 'iife'` or ensure your output format supports global variable assignments.","message":"The plugin emits `module.exports = window.VariableName` for CJS output; may cause issues with Rollup's `output.format: 'es'` if not configured correctly.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"For webpack, use built-in `externals` config; for esbuild, use `external` option with `globalName`.","message":"Only works with Rollup; not compatible with other bundlers like webpack or esbuild.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Pin to exact version and test upgrades thoroughly.","message":"Plugin is at v0.0.1; API may change in future versions without major version bump.","severity":"deprecated","affected_versions":">=0.0.1 <1.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use `const { externals } = require('rollup-plugin-externals')` instead of `const externals = require('rollup-plugin-externals')`.","cause":"CommonJS require used without destructuring, getting the module object instead of the externals function.","error":"TypeError: (0 , rp.default) is not a function"},{"fix":"Ensure rollup-plugin-externals is installed as a direct devDependency, and delete node_modules/.cache if needed.","cause":"The plugin's internal import resolution fails when used as a transitive dependency or with hoisted node_modules.","error":"RollupError: Could not resolve './some-internal-module' from 'node_modules/rollup-plugin-externals/index.js'"},{"fix":"Set Rollup's output.format to 'cjs' or 'iife' and ensure the target environment supports `module`.","cause":"Using the plugin with output.format: 'es' or 'iife' but the plugin generates CJS-style stubs.","error":"Uncaught ReferenceError: module is not defined","affected_versions":">=0.0.1"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}