Registry / devops / webpack-node-externals

webpack-node-externals

JSON →
library3.0.0jsnpmunverified

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).

npm install webpack-node-externals
INSTALL
IMPORT
SIG · WEBPACK-NODE-EXTER
W
webpack-node-externals
devopsjavascriptv3.0.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.

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.
fix
Replace '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.
fix
Ensure 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.
fix
Use '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.
fix
Add the alias name to the 'allowlist' array.
affects: *
Errors
Common errors & fixes
Error: Cannot find module 'webpack-node-externals'
The package is not installed.
fix
npm install webpack-node-externals --save-dev
TypeError: nodeExternals is not a function
Incorrect import style, e.g., import { nodeExternals } from ...
fix
Use 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.
fix
Use nodeExternals() in the externals configuration.
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
10
Resources
webpack-node-externals — npm install webpack-node-externals · libregistry