{"id":21292,"library":"esbuild-shim-plugin","title":"esbuild-shim-plugin","description":"An esbuild plugin that polyfills import.meta.url for ESM modules and require/__filename/__dirname for CommonJS modules. Stable v1.0.3, released 2023. Lightweight, zero dependencies, ships TypeScript types. Key differentiator: solves the common problem of using Node.js module globals when bundling with esbuild, especially useful for mixed CJS/ESM codebases. Release cadence is low; no major changes expected.","status":"active","version":"1.0.3","language":"javascript","source_language":"en","source_url":"https://github.com/shahradelahi/esbuild-shim-plugin","tags":["javascript","esbuild","plugin","shim","import","require","typescript"],"install":[{"cmd":"npm install esbuild-shim-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add esbuild-shim-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add esbuild-shim-plugin","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Default export is not available; use named import. CommonJS require fails because esbuild-shim-plugin is ESM-only.","wrong":"const shimPlugin = require('esbuild-shim-plugin')","symbol":"shimPlugin","correct":"import { shimPlugin } from 'esbuild-shim-plugin'"},{"note":"The package exports a named export, not a default export. Attempting default import will result in undefined.","wrong":"import shimPlugin from 'esbuild-shim-plugin'","symbol":"shimPlugin","correct":"import { shimPlugin } from 'esbuild-shim-plugin'"},{"note":"The package is ESM-only since v1.0.0, so require() is not supported in CommonJS contexts.","wrong":"const { shimPlugin } = require('esbuild-shim-plugin')","symbol":"shimPlugin","correct":"import { shimPlugin } from 'esbuild-shim-plugin'"}],"quickstart":{"code":"import { build } from 'esbuild';\nimport { shimPlugin } from 'esbuild-shim-plugin';\n\nawait build({\n  entryPoints: ['src/index.ts'],\n  bundle: true,\n  format: 'esm',\n  outfile: 'dist/index.js',\n  plugins: [shimPlugin()],\n});","lang":"typescript","description":"Bundles an ESM project using esbuild with shimPlugin to polyfill import.meta.url, require, __filename, and __dirname."},"warnings":[{"fix":"Only use the plugin when you actually need to access require, __filename, __dirname, or import.meta.url in bundled code. Consider alternatives like setting the 'platform' to 'node'.","message":"shimPlugin() adds polyfill code that may increase bundle size and affect runtime performance.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use dynamic import() or ensure your project is configured for ESM.","message":"The package is ESM-only and cannot be required() in CommonJS contexts.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Pin to a specific version if you rely on exact behavior.","message":"No public API changes are expected, but no stability guarantees are documented.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Test plugin order and compatibility when using multiple esbuild plugins.","message":"The plugin may conflict with other esbuild plugins that modify import/require behavior.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run `npm install esbuild-shim-plugin --save-dev` or `pnpm add -D esbuild-shim-plugin`.","cause":"Module not installed or not in node_modules.","error":"Cannot find module 'esbuild-shim-plugin'"},{"fix":"Use `import { shimPlugin } from 'esbuild-shim-plugin'` and ensure your project uses ESM or dynamic import.","cause":"Trying to use require() to load the ESM-only package.","error":"require() of ES Module esbuild-shim-plugin from CJS not supported"},{"fix":"Use `import { shimPlugin } from 'esbuild-shim-plugin'` instead of `import shimPlugin from 'esbuild-shim-plugin'`.","cause":"Default import used when the package only provides named exports.","error":"The requested module 'esbuild-shim-plugin' does not provide an export named 'default'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}