Registry / devops / esbuild-plugin-globals

esbuild-plugin-globals

JSON →
library0.2.0jsnpmunverified

An esbuild plugin that replicates Webpack's externals functionality, allowing you to exclude certain modules from the bundle and replace them with global variables. Current stable version 0.2.0. It supports string patterns and RegExp with resolver functions for complex cases. Differs from native esbuild's 'external' by providing per-module global variable mapping, similar to Webpack's externals. Ships TypeScript declarations.

npm install esbuild-plugin-globals
INSTALL
IMPORT
SIG · ESBUILD-PLUGIN-GLO
E
esbuild-plugin-globals
devopsjavascriptv0.2.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 GlobalsPlugin from 'esbuild-plugin-globals'
const GlobalsPlugin = require('esbuild-plugin-globals')
ESM-only; requires module resolution or bundling.
default
const GlobalsPlugin = require('esbuild-plugin-globals').default
const GlobalsPlugin = require('esbuild-plugin-globals')
For CommonJS usage, you must access .default property.
GlobalsPlugin
import GlobalsPlugin from 'esbuild-plugin-globals'
import { GlobalsPlugin } from 'esbuild-plugin-globals'
Named export not available; use default import.

Demonstrates basic usage: mapping 'react', 'react-dom', and 'lodash' to global variables in an esbuild bundle.

import esbuild from 'esbuild'; import GlobalsPlugin from 'esbuild-plugin-globals'; await esbuild.build({ entryPoints: ['src/index.ts'], bundle: true, plugins: [ GlobalsPlugin({ 'react': 'React', 'react-dom': 'ReactDOM', 'lodash': '_' }) ], outfile: 'bundle.js' }); console.log('Built with globals');
Debug
Known issues
gotchaPatterns are matched against module specifiers, not file paths. Ensure your import statements use the exact module name.
fix
Verify that the keys in the globals object match the import specifier exactly, e.g., 'react', not './react'.
affects: >=0.1.0
breakingIn version 0.2.0, TypeScript type definitions were added. Using previous versions without @types/esbuild-plugin-globals may require manual type definitions.
fix
Upgrade to 0.2.0 or later.
affects: <0.2.0
deprecatedThe plugin does not support asynchronous resolver functions. Use only synchronous string or function returns.
fix
Ensure resolver functions return a string synchronously; async functions will not work.
affects: >=0.1.0
Errors
Common errors & fixes
Error: The plugin "esbuild-plugin-globals" must be constructed with a non-empty object
Calling GlobalsPlugin() without arguments or with an empty object.
fix
Pass an object with at least one module mapping.
Error: Module "react" has been externalized but not found in globals
The plugin is not mapping a module that is set as external elsewhere.
fix
Either add the module to the globals object or ensure it's not external.
TypeError: globals[moduleName] is not a function
Using a RegExp pattern with a value that is not a string or function.
fix
Ensure the value for a regex key is a function that accepts the module name and returns a string (or undefined).
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies
esbuildrequiredpeer dependency, plugin only works with esbuild
Agent activity
5 hits · last 30 days
node
4
Resources
esbuild-plugin-globals — npm install esbuild-plugin-globals · libregistry