{"id":20239,"library":"node-polyfill-webpack-plugin","title":"node-polyfill-webpack-plugin","description":"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.","status":"active","version":"4.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/Richienb/node-polyfill-webpack-plugin","tags":["javascript","webpack","webpack-plugin","node","polyfill","typescript"],"install":[{"cmd":"npm install node-polyfill-webpack-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add node-polyfill-webpack-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add node-polyfill-webpack-plugin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required as a peer dependency; plugin hooks into Webpack compilation","package":"webpack","optional":false}],"imports":[{"note":"Package is CJS-only, does not export ESM. Use require() in Node.","wrong":"import NodePolyfillPlugin from 'node-polyfill-webpack-plugin';","symbol":"NodePolyfillPlugin","correct":"const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');"},{"note":"The plugin is a constructor, not an object with a default property.","wrong":"new NodePolyfillPlugin.default()","symbol":"NodePolyfillPlugin","correct":"new NodePolyfillPlugin()"},{"note":"Named import from CJS package is not supported in native ESM.","wrong":"import { NodePolyfillPlugin } from 'node-polyfill-webpack-plugin';","symbol":"NodePolyfillPlugin","correct":"const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');"}],"quickstart":{"code":"// webpack.config.js\nconst path = require('path');\nconst NodePolyfillPlugin = require('node-polyfill-webpack-plugin');\n\nmodule.exports = {\n  entry: './src/index.js',\n  output: {\n    path: path.resolve(__dirname, 'dist'),\n  },\n  plugins: [\n    new NodePolyfillPlugin()\n  ]\n};","lang":"javascript","description":"Basic webpack config that adds Node.js core module polyfills to a browser bundle."},"warnings":[{"fix":"Use 'additionalAliases' option to explicitly include them.","message":"console, domain, process, and internal stream modules are no longer polyfilled by default in v4.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Rename 'includeAliases' to 'additionalAliases' in your config.","message":"The 'includeAliases' option has been renamed to 'additionalAliases' in v4.","severity":"deprecated","affected_versions":">=4.0.0"},{"fix":"Upgrade Node.js to version 14 or higher.","message":"Node.js 12 support dropped; requires Node >=14.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Avoid using 'fs' in browser code or provide a custom mock via webpack aliases.","message":"fs module resolves to an empty object (not polyfilled) because it cannot be implemented in the browser.","severity":"gotcha","affected_versions":">=4.0.0"},{"fix":"If using Webpack 4, you don't need this plugin.","message":"The plugin only works with Webpack 5; Webpack 4 already had Node polyfills built in.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"List all required aliases in 'onlyAliases' array, including defaults if still needed.","message":"Using 'onlyAliases' overrides default polyfills; you must include everything you need manually.","severity":"gotcha","affected_versions":">=4.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Add NodePolyfillPlugin to webpack plugins.","cause":"Webpack 5 no longer polyfills Node core modules; plugin not added or not configured correctly.","error":"Module not found: Error: Can't resolve 'crypto' in '/path/to/project/src'"},{"fix":"Use new NodePolyfillPlugin() instead of NodePolyfillPlugin()","cause":"CommonJS require returns the class itself, not a factory function.","error":"Class constructor NodePolyfillPlugin cannot be invoked without 'new'"},{"fix":"Use require() or configure bundler to handle CJS interop.","cause":"Using ES module import syntax with a CJS-only package without proper configuration.","error":"TypeError: NodePolyfillPlugin is not a constructor"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}