package
Polyfills nodejs builtin modules and globals for the browser.
npm install esbuild-plugins-node-modules-polyfillGitHub-flavored package documentation.
Across all versions, last 30 days.
2,744,326 in 30 days
Runtime metadata.
Tagged topics.
Latest published Aug 5, 2026
latest
Estimated unpacked size across 12 packages.
7.4 MB
Includes dependencies.
3 direct · 1 outdated
Polyfills nodejs builtin modules and globals for the browser.
node: protocolbrowserpackage.jsonnpm install --save-dev esbuild-plugins-node-modules-polyfill
import { nodeModulesPolyfillPlugin } from 'esbuild-plugins-node-modules-polyfill';
import { build } from 'esbuild';
build({
plugins: [nodeModulesPolyfillPlugin()],
});import { nodeModulesPolyfillPlugin } from 'esbuild-plugins-node-modules-polyfill';
import { build } from 'esbuild';
build({
plugins: [
nodeModulesPolyfillPlugin({
globals: {
process: true,
Buffer: true,
},
}),
],
});[!Note] If you are utilizing the
modulesoption, ensure that you include polyfills for the global modules you are using.
import { nodeModulesPolyfillPlugin } from 'esbuild-plugins-node-modules-polyfill';
import { build } from 'esbuild';
build({
plugins: [
nodeModulesPolyfillPlugin({
modules: ['crypto'],
}),
],
});import { nodeModulesPolyfillPlugin } from 'esbuild-plugins-node-modules-polyfill';
import { build } from 'esbuild';
build({
plugins: [
nodeModulesPolyfillPlugin({
modules: {
crypto: true,
fs: false,
},
}),
],
});You can provide custom polyfill implementations for specific modules. This is useful when you need to customize the behavior of a polyfill for your specific use case.
import { nodeModulesPolyfillPlugin } from 'esbuild-plugins-node-modules-polyfill';
import { build } from 'esbuild';
build({
plugins: [
nodeModulesPolyfillPlugin({
overrides: {
process: './my-custom-process-polyfill.js',
},
}),
],
});The custom polyfill file should export a default export with your implementation:
// my-custom-process-polyfill.js
const customProcess = {
env: {},
version: 'v1.0.0',
platform: 'browser',
stdout: {
write: (data) => console.log(data),
},
// ... other process properties
};
export default customProcess;[!Note] Custom overrides work with both
processandnode:processstyle imports. You can specify the override with or without thenode:prefix.
[!Important]
- File paths should be absolute paths or relative to the project root (where esbuild is executed), not relative to the configuration file. This is important because esbuild will resolve these paths, and relative paths might not work as expected if you run the build command from a different directory.
- If a module is specified in both
overridesandmodulesoptions (e.g.,overrides: { process: './custom.js' }andmodules: { process: 'empty' }), the override takes precedence and themodulesconfiguration for that module will be ignored.
import { nodeModulesPolyfillPlugin } from 'esbuild-plugins-node-modules-polyfill';
import { build } from 'esbuild';
build({
plugins: [
nodeModulesPolyfillPlugin({
modules: {
fs: 'empty',
crypto: true,
},
}),
],
});import { nodeModulesPolyfillPlugin } from 'esbuild-plugins-node-modules-polyfill';
import { build } from 'esbuild';
build({
plugins: [
nodeModulesPolyfillPlugin({
fallback: 'empty',
}),
],
});import { nodeModulesPolyfillPlugin } from 'esbuild-plugins-node-modules-polyfill';
import { build } from 'esbuild';
build({
plugins: [
nodeModulesPolyfillPlugin({
fallback: 'empty',
modules: {
crypto: true,
},
}),
],
});[!Important] The
writeoption inesbuildmust befalseto support this.
import { nodeModulesPolyfillPlugin } from 'esbuild-plugins-node-modules-polyfill';
import { build } from 'esbuild';
const buildResult = await build({
write: false,
plugins: [
nodeModulesPolyfillPlugin({
modules: {
crypto: 'error',
path: true,
},
}),
],
});[!Important] The
writeoption inesbuildmust befalseto support this.
import { nodeModulesPolyfillPlugin } from 'esbuild-plugins-node-modules-polyfill';
import { build } from 'esbuild';
const buildResult = await build({
write: false,
plugins: [
nodeModulesPolyfillPlugin({
fallback: 'error',
modules: {
path: true,
},
}),
],
});Return an esbuild PartialMessage object from the formatError function to override any properties of the default error message.
[!Important] The
writeoption inesbuildmust befalseto support this.
import { nodeModulesPolyfillPlugin } from 'esbuild-plugins-node-modules-polyfill';
import { build } from 'esbuild';
const buildResult = await build({
write: false,
plugins: [
nodeModulesPolyfillPlugin({
fallback: 'error',
modules: {
path: true,
},
formatError({ moduleName, importer, polyfillExists }) {
return {
text: polyfillExists
? `Polyfill has not been configured for "${moduleName}", imported by "${importer}"`
: `Polyfill does not exist for "${moduleName}", imported by "${importer}"`,
};
},
}),
],
});If you want to support me by donating, you can do so by using any of the following methods. Thank you very much in advance!
Thanks goes to these wonderful people: