An esbuild plugin that polyfills Node.js built-in modules (e.g., buffer, crypto, path, fs, stream, events) and globals for browser environments. Current stable version is 1.8.1, maintained actively with releases roughly monthly. It uses the modern-node-polyfills npm package internally and supports esbuild peer dependencies between 0.14.x and 0.27.x. Key differentiators: it is the most comprehensive and actively maintained esbuild polyfill plugin, supports custom error formatting, empty fallbacks, and the `browser` field in package.json. It also injects Node.js globals like `process` and `Buffer` via esbuild's `inject` functionality.
npm install esbuild-plugins-node-modules-polyfillNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows ESM import and usage of the plugin with esbuild build. Includes optional configuration of specific modules.
Explicitly set `modules: { 'moduleName': true }` to allow polyfill, or `false` to disable. Or use `onError` option to customize error handling.Change `require()` to `import`. If your project is CJS, you can use dynamic import: `const nodeModulesPolyfill = (await import('esbuild-plugins-node-modules-polyfill')).default;`Upgrade Node.js to version 14.0.0 or later.
Use esbuild's `inject` option with paths to polyfill files, e.g., `inject: ['./node_modules/.../process.js']`.
Normalize module names: prefer without `node:` prefix, e.g., `modules: { crypto: true }`.Switch to `import` or use `const nodeModulesPolyfill = (await import('esbuild-plugins-node-modules-polyfill')).default;` inside an async function.Downgrade esbuild to 0.27.x or wait for a newer release of the plugin that supports esbuild 0.28.
Use default import: `import nodeModulesPolyfill from 'esbuild-plugins-node-modules-polyfill'` and call `nodeModulesPolyfill()`.