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
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
nodeExternals
✓ const nodeExternals = require('webpack-node-externals');
✗ import nodeExternals from 'webpack-node-externals';
This package uses CommonJS exports even in v3. For ESM projects, use dynamic import or keep require().
nodeExternals (named import attempt)
✓ const nodeExternals = require('webpack-node-externals');
✗ import { nodeExternals } from 'webpack-node-externals';
There is no named export; the default export is a function. Named import will result in undefined.
nodeExternals with allowlist
✓ externals: [nodeExternals({ allowlist: ['module'] })]
✗ externals: nodeExternals({ allowlist: ['module'] })
The result must be placed inside an array in the webpack externals configuration unless it's the only entry.
Minimal webpack configuration to bundle a Node.js application while excluding node_modules.
// webpack.config.js
const path = require('path');
const nodeExternals = require('webpack-node-externals');
module.exports = {
target: 'node', // required for Node.js built-ins (path, fs, etc.)
externals: [nodeExternals()], // exclude all node_modules
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
},
};
// For Webpack 5, replace target with:
// externalsPresets: { node: true }
Debug
Known issues
breakingIn v2.0.0, the 'whitelist' option was renamed to 'allowlist' and the old name is no longer supported.fixReplace 'whitelist' with 'allowlist' in your configuration.
affects: >=2.0.0
breakingIn v3.0.0, support for Node.js < 6 was dropped and the code syntax changed to ES6.fixEnsure your Node.js version is >= 6. No code changes required for users; the API remains compatible.
affects: >=3.0.0
deprecatedUsing 'target: 'node'' for Webpack 5 is discouraged.fixUse 'externalsPresets: { node: true }' instead. affects: >=2.5.0 (Webpack 5)
gotchaIf you have aliases in your webpack config with the same name as a node_module, the module will be excluded unless explicitly allowlisted.fixAdd the alias name to the 'allowlist' array.
affects: *
Errors
Common errors & fixes
Error: Cannot find module 'webpack-node-externals'
The package is not installed.
fixnpm install webpack-node-externals --save-dev
TypeError: nodeExternals is not a function
Incorrect import style, e.g., import { nodeExternals } from ...
fixUse const nodeExternals = require('webpack-node-externals'); Critical dependency: the request of a dependency is an expression
Webpack cannot statically analyze require() calls when node_modules are included in the bundle.
fixUse nodeExternals() in the externals configuration.
Audit
Dependencies
No dependency data recorded yet.