An esbuild plugin that automatically externalizes all Node.js built-in modules and dependencies from node_modules, so they are not bundled. Version 1.22.0 supports esbuild 0.12–0.28. It differentiates from manual externals handling by scanning package.json dependencies, devDependencies, peerDependencies, and optionalDependencies, and also externalizes Node built-ins like 'fs', 'path', etc. The plugin handles ESM and CJS outputs correctly, and works well with monorepos. It is often used alongside other esbuild plugins for Node.js bundling where the goal is to keep dependencies out of the bundle for faster builds and smaller output. The package has type definitions built-in and is released on a as-needed cadence.
npm install esbuild-node-externalsNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Basic esbuild configuration using esbuild-node-externals to exclude Node built-ins and dependencies from the bundle.
Ensure all dependencies you want external are listed in your package.json. Alternatively, use the `allowList` option to include specific packages that should still be bundled.
Replace `modulesDir` with `packagePath` in your plugin options.
Update imports to `import nodeExternals from 'esbuild-node-externals'` and ensure your project uses ESM or a bundler that handles ESM.
Only use `esbuild-node-externals` when `platform: 'node'` or you intend to keep built-ins external.
Run `npm install esbuild-node-externals --save-dev` and ensure import is correct: `import nodeExternals from 'esbuild-node-externals'`.
Add `allowList: ['express']` to the plugin options or remove 'express' from dependencies.
Use `import nodeExternals from 'esbuild-node-externals'` (default import) or `import { nodeExternals } from 'esbuild-node-externals'` (named).