Registry / http-networking / esbuild-shim-plugin

esbuild-shim-plugin

JSON →
library1.0.3jsnpmunverified

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.

npm install esbuild-shim-plugin
INSTALL
IMPORT
SIG · ESBUILD-SHIM-PLUGI
E
esbuild-shim-plugin
http-networkingjavascriptv1.0.3
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.

shimPlugin
import { shimPlugin } from 'esbuild-shim-plugin'
const shimPlugin = require('esbuild-shim-plugin')
Default export is not available; use named import. CommonJS require fails because esbuild-shim-plugin is ESM-only.
shimPlugin
import { shimPlugin } from 'esbuild-shim-plugin'
import shimPlugin from 'esbuild-shim-plugin'
The package exports a named export, not a default export. Attempting default import will result in undefined.
shimPlugin
import { shimPlugin } from 'esbuild-shim-plugin'
const { shimPlugin } = require('esbuild-shim-plugin')
The package is ESM-only since v1.0.0, so require() is not supported in CommonJS contexts.

Bundles an ESM project using esbuild with shimPlugin to polyfill import.meta.url, require, __filename, and __dirname.

import { build } from 'esbuild'; import { shimPlugin } from 'esbuild-shim-plugin'; await build({ entryPoints: ['src/index.ts'], bundle: true, format: 'esm', outfile: 'dist/index.js', plugins: [shimPlugin()], });
Debug
Known issues
gotchashimPlugin() adds polyfill code that may increase bundle size and affect runtime performance.
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'.
affects: >=1.0.0
breakingThe package is ESM-only and cannot be required() in CommonJS contexts.
fix
Use dynamic import() or ensure your project is configured for ESM.
affects: >=1.0.0
deprecatedNo public API changes are expected, but no stability guarantees are documented.
fix
Pin to a specific version if you rely on exact behavior.
affects: >=1.0.0
gotchaThe plugin may conflict with other esbuild plugins that modify import/require behavior.
fix
Test plugin order and compatibility when using multiple esbuild plugins.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'esbuild-shim-plugin'
Module not installed or not in node_modules.
fix
Run `npm install esbuild-shim-plugin --save-dev` or `pnpm add -D esbuild-shim-plugin`.
require() of ES Module esbuild-shim-plugin from CJS not supported
Trying to use require() to load the ESM-only package.
fix
Use `import { shimPlugin } from 'esbuild-shim-plugin'` and ensure your project uses ESM or dynamic import.
The requested module 'esbuild-shim-plugin' does not provide an export named 'default'
Default import used when the package only provides named exports.
fix
Use `import { shimPlugin } from 'esbuild-shim-plugin'` instead of `import shimPlugin from 'esbuild-shim-plugin'`.
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
esbuild-shim-plugin — npm install esbuild-shim-plugin · libregistry