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-pluginVerified import paths — ran on the pinned version, not inferred.
Basic webpack config that adds Node.js core module polyfills to a browser bundle.
Use 'additionalAliases' option to explicitly include them.
Rename 'includeAliases' to 'additionalAliases' in your config.
Upgrade Node.js to version 14 or higher.
Avoid using 'fs' in browser code or provide a custom mock via webpack aliases.
If using Webpack 4, you don't need this plugin.
List all required aliases in 'onlyAliases' array, including defaults if still needed.
Add NodePolyfillPlugin to webpack plugins.
Use new NodePolyfillPlugin() instead of NodePolyfillPlugin()
Use require() or configure bundler to handle CJS interop.