Registry / devops / node-polyfill-webpack-plugin

node-polyfill-webpack-plugin

JSON →
library4.1.0jsnpmunverified

Webpack 5 removed automatic Node.js core module polyfills, breaking many packages that rely on them. This plugin restores those polyfills (Buffer, process, crypto, path, etc.) by injecting lightweight browser-compatible implementations. Current stable version is 4.1.0, released in 2024. Requires Node >=14 and Webpack >=5. Compared to manual fallbacks or patch-package, it provides a single plugin configuration. v4 dropped several modules from defaults (console, domain, process, internal streams) and renamed includeAliases to additionalAliases. Ships TypeScript definitions.

npm install node-polyfill-webpack-plugin
INSTALL
IMPORT
SIG · NODE-POLYFILL-WEBP
N
node-polyfill-webpack-plugin
devopsjavascriptv4.1.0
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 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

NodePolyfillPlugin
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
import NodePolyfillPlugin from 'node-polyfill-webpack-plugin';
Package is CJS-only, does not export ESM. Use require() in Node.
NodePolyfillPlugin
new NodePolyfillPlugin()
new NodePolyfillPlugin.default()
The plugin is a constructor, not an object with a default property.
NodePolyfillPlugin
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
import { NodePolyfillPlugin } from 'node-polyfill-webpack-plugin';
Named import from CJS package is not supported in native ESM.

Basic webpack config that adds Node.js core module polyfills to a browser bundle.

// webpack.config.js const path = require('path'); const NodePolyfillPlugin = require('node-polyfill-webpack-plugin'); module.exports = { entry: './src/index.js', output: { path: path.resolve(__dirname, 'dist'), }, plugins: [ new NodePolyfillPlugin() ] };
Debug
Known issues
breakingconsole, domain, process, and internal stream modules are no longer polyfilled by default in v4.
fix
Use 'additionalAliases' option to explicitly include them.
affects: >=4.0.0
deprecatedThe 'includeAliases' option has been renamed to 'additionalAliases' in v4.
fix
Rename 'includeAliases' to 'additionalAliases' in your config.
affects: >=4.0.0
breakingNode.js 12 support dropped; requires Node >=14.
fix
Upgrade Node.js to version 14 or higher.
affects: >=3.0.0
gotchafs module resolves to an empty object (not polyfilled) because it cannot be implemented in the browser.
fix
Avoid using 'fs' in browser code or provide a custom mock via webpack aliases.
affects: >=4.0.0
gotchaThe plugin only works with Webpack 5; Webpack 4 already had Node polyfills built in.
fix
If using Webpack 4, you don't need this plugin.
affects: >=1.0.0
gotchaUsing 'onlyAliases' overrides default polyfills; you must include everything you need manually.
fix
List all required aliases in 'onlyAliases' array, including defaults if still needed.
affects: >=4.0.0
Errors
Common errors & fixes
Module not found: Error: Can't resolve 'crypto' in '/path/to/project/src'
Webpack 5 no longer polyfills Node core modules; plugin not added or not configured correctly.
fix
Add NodePolyfillPlugin to webpack plugins.
Class constructor NodePolyfillPlugin cannot be invoked without 'new'
CommonJS require returns the class itself, not a factory function.
fix
Use new NodePolyfillPlugin() instead of NodePolyfillPlugin()
TypeError: NodePolyfillPlugin is not a constructor
Using ES module import syntax with a CJS-only package without proper configuration.
fix
Use require() or configure bundler to handle CJS interop.
Upgrade
Version history
4.1.0latest on npm
Audit
Dependencies
webpackrequiredRequired as a peer dependency; plugin hooks into Webpack compilation
Agent activity
2 hits · last 30 days
node
2
Resources
node-polyfill-webpack-plugin — npm install node-polyfill-webpack-plugin · libregistry