{"id":21248,"library":"esbuild-plugin-globals","title":"esbuild-plugin-globals","description":"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.","status":"active","version":"0.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/a-b-r-o-w-n/esbuild-plugin-globals","tags":["javascript","esbuild","esbuild-plugin","typescript"],"install":[{"cmd":"npm install esbuild-plugin-globals","lang":"bash","label":"npm"},{"cmd":"yarn add esbuild-plugin-globals","lang":"bash","label":"yarn"},{"cmd":"pnpm add esbuild-plugin-globals","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency, plugin only works with esbuild","package":"esbuild","optional":false}],"imports":[{"note":"ESM-only; requires module resolution or bundling.","wrong":"const GlobalsPlugin = require('esbuild-plugin-globals')","symbol":"default","correct":"import GlobalsPlugin from 'esbuild-plugin-globals'"},{"note":"For CommonJS usage, you must access .default property.","wrong":"const GlobalsPlugin = require('esbuild-plugin-globals')","symbol":"default","correct":"const GlobalsPlugin = require('esbuild-plugin-globals').default"},{"note":"Named export not available; use default import.","wrong":"import { GlobalsPlugin } from 'esbuild-plugin-globals'","symbol":"GlobalsPlugin","correct":"import GlobalsPlugin from 'esbuild-plugin-globals'"}],"quickstart":{"code":"import esbuild from 'esbuild';\nimport GlobalsPlugin from 'esbuild-plugin-globals';\n\nawait esbuild.build({\n  entryPoints: ['src/index.ts'],\n  bundle: true,\n  plugins: [\n    GlobalsPlugin({\n      'react': 'React',\n      'react-dom': 'ReactDOM',\n      'lodash': '_'\n    })\n  ],\n  outfile: 'bundle.js'\n});\nconsole.log('Built with globals');","lang":"typescript","description":"Demonstrates basic usage: mapping 'react', 'react-dom', and 'lodash' to global variables in an esbuild bundle."},"warnings":[{"fix":"Verify that the keys in the globals object match the import specifier exactly, e.g., 'react', not './react'.","message":"Patterns are matched against module specifiers, not file paths. Ensure your import statements use the exact module name.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Upgrade to 0.2.0 or later.","message":"In version 0.2.0, TypeScript type definitions were added. Using previous versions without @types/esbuild-plugin-globals may require manual type definitions.","severity":"breaking","affected_versions":"<0.2.0"},{"fix":"Ensure resolver functions return a string synchronously; async functions will not work.","message":"The plugin does not support asynchronous resolver functions. Use only synchronous string or function returns.","severity":"deprecated","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Pass an object with at least one module mapping.","cause":"Calling GlobalsPlugin() without arguments or with an empty object.","error":"Error: The plugin \"esbuild-plugin-globals\" must be constructed with a non-empty object"},{"fix":"Either add the module to the globals object or ensure it's not external.","cause":"The plugin is not mapping a module that is set as external elsewhere.","error":"Error: Module \"react\" has been externalized but not found in globals"},{"fix":"Ensure the value for a regex key is a function that accepts the module name and returns a string (or undefined).","cause":"Using a RegExp pattern with a value that is not a string or function.","error":"TypeError: globals[moduleName] is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}