{"id":20803,"library":"webpack-node-externals","title":"webpack-node-externals","description":"Webpack plugin to automatically exclude node_modules from the bundle when building Node.js backends. Current stable version is 3.0.0, actively maintained with releases every few months. Unlike manual externals configuration, it scans node_modules and generates exclusions automatically, supporting allowlisting, custom import types, and reading dependencies from package.json. Key differentiator: zero-config for the common case, yet fully configurable. Requires Webpack (tested with v4 and v5).","status":"active","version":"3.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/liady/webpack-node-externals","tags":["javascript","webpack","node_modules","node","bundle","externals"],"install":[{"cmd":"npm install webpack-node-externals","lang":"bash","label":"npm"},{"cmd":"yarn add webpack-node-externals","lang":"bash","label":"yarn"},{"cmd":"pnpm add webpack-node-externals","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package uses CommonJS exports even in v3. For ESM projects, use dynamic import or keep require().","wrong":"import nodeExternals from 'webpack-node-externals';","symbol":"nodeExternals","correct":"const nodeExternals = require('webpack-node-externals');"},{"note":"There is no named export; the default export is a function. Named import will result in undefined.","wrong":"import { nodeExternals } from 'webpack-node-externals';","symbol":"nodeExternals (named import attempt)","correct":"const nodeExternals = require('webpack-node-externals');"},{"note":"The result must be placed inside an array in the webpack externals configuration unless it's the only entry.","wrong":"externals: nodeExternals({ allowlist: ['module'] })","symbol":"nodeExternals with allowlist","correct":"externals: [nodeExternals({ allowlist: ['module'] })]"}],"quickstart":{"code":"// webpack.config.js\nconst path = require('path');\nconst nodeExternals = require('webpack-node-externals');\n\nmodule.exports = {\n  target: 'node', // required for Node.js built-ins (path, fs, etc.)\n  externals: [nodeExternals()], // exclude all node_modules\n  entry: './src/index.js',\n  output: {\n    path: path.resolve(__dirname, 'dist'),\n    filename: 'bundle.js',\n  },\n};\n\n// For Webpack 5, replace target with:\n// externalsPresets: { node: true }","lang":"javascript","description":"Minimal webpack configuration to bundle a Node.js application while excluding node_modules."},"warnings":[{"fix":"Replace 'whitelist' with 'allowlist' in your configuration.","message":"In v2.0.0, the 'whitelist' option was renamed to 'allowlist' and the old name is no longer supported.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Ensure your Node.js version is >= 6. No code changes required for users; the API remains compatible.","message":"In v3.0.0, support for Node.js < 6 was dropped and the code syntax changed to ES6.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Use 'externalsPresets: { node: true }' instead.","message":"Using 'target: 'node'' for Webpack 5 is discouraged.","severity":"deprecated","affected_versions":">=2.5.0 (Webpack 5)"},{"fix":"Add the alias name to the 'allowlist' array.","message":"If you have aliases in your webpack config with the same name as a node_module, the module will be excluded unless explicitly allowlisted.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"npm install webpack-node-externals --save-dev","cause":"The package is not installed.","error":"Error: Cannot find module 'webpack-node-externals'"},{"fix":"Use const nodeExternals = require('webpack-node-externals');","cause":"Incorrect import style, e.g., import { nodeExternals } from ...","error":"TypeError: nodeExternals is not a function"},{"fix":"Use nodeExternals() in the externals configuration.","cause":"Webpack cannot statically analyze require() calls when node_modules are included in the bundle.","error":"Critical dependency: the request of a dependency is an expression"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}