{"id":25336,"library":"esbuild-plugin-external-global","title":"esbuild-plugin-external-global","description":"An esbuild plugin that maps external modules to global variables, enabling bundle-size reduction by excluding dependencies like React, ReactDOM, or jQuery and referencing them via globals such as window.React. Version 1.0.1 is stable with minimal API surface. It provides a simple mapping object where keys are module names and values are global variable expressions. The plugin is commonly used in library builds where certain dependencies are provided by the host environment. It has TypeScript types and works with both CJS and ESM esbuild configurations. Compared to similar plugins like esbuild-plugin-externalize, this one focuses specifically on global variable fallbacks rather than file-based externals.","status":"active","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/yanm1ng/esbuild-plugin-external-global","tags":["javascript","esbuild","plugin","external","typescript"],"install":[{"cmd":"npm install esbuild-plugin-external-global","lang":"bash","label":"npm"},{"cmd":"yarn add esbuild-plugin-external-global","lang":"bash","label":"yarn"},{"cmd":"pnpm add esbuild-plugin-external-global","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package exports a named export, not default. CJS require destructuring works but ESM import is recommended.","wrong":"const externalGlobalPlugin = require('esbuild-plugin-external-global')","symbol":"externalGlobalPlugin","correct":"import { externalGlobalPlugin } from 'esbuild-plugin-external-global'"},{"note":"esbuild is a peer dependency. Both CJS and ESM supported; use dynamic import for newer esbuild versions.","wrong":"const esbuild = require('esbuild')","symbol":"esbuild","correct":"import * as esbuild from 'esbuild'"},{"note":"TypeScript users can import the type for type-checking the plugin options.","wrong":"","symbol":"externalGlobalPlugin (type)","correct":"import type { ExternalGlobalPlugin } from 'esbuild-plugin-external-global'"}],"quickstart":{"code":"import * as esbuild from 'esbuild';\nimport { externalGlobalPlugin } from 'esbuild-plugin-external-global';\n\nawait esbuild.build({\n  entryPoints: ['src/index.js'],\n  bundle: true,\n  outfile: 'dist/bundle.js',\n  plugins: [\n    externalGlobalPlugin({\n      'react': 'window.React',\n      'react-dom': 'window.ReactDOM'\n    })\n  ]\n});","lang":"typescript","description":"Build a bundle excluding React and ReactDOM, expecting them as globals."},"warnings":[{"fix":"Replace 'externalGlobal' with 'externalGlobalPlugin' in imports and usage.","message":"In v1.0.0, the function name changed from 'externalGlobal' to 'externalGlobalPlugin'.","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"Add 'external: [\"react\", \"react-dom\"]' to esbuild options.","message":"The plugin does not automatically set 'external' option; you must mark those packages as external in esbuild config.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use 'window.React' not '\"window.React\"'.","message":"Global variable expressions must evaluate to a function/object, not a string literal; incorrect quotes cause runtime errors.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Change 'import externalGlobalPlugin from...' to 'import { externalGlobalPlugin } from...'.","cause":"Using default import instead of named import.","error":"Error: Build failed with 1 error: error: No matching export in \"node_modules/esbuild-plugin-external-global/lib/index.js\" for import \"default\""},{"fix":"Ensure plugin is an object with setup function: wrap result of externalGlobalPlugin() in brackets: plugins: [externalGlobalPlugin({...})].","cause":"Plugin not added to esbuild plugins array correctly.","error":"TypeError: Cannot read properties of undefined (reading 'onResolve')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}