# esbuild-node-externals

Latest version **2.0.0** (published 2026-08-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install esbuild-node-externals
pnpm add esbuild-node-externals
yarn add esbuild-node-externals
bun add esbuild-node-externals
```

## Health

**Score 65/100 (B)** — status: active.

Positive: esm support; no vulnerabilities; has provenance; recently updated; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2026-08-04 |
| First published | 2020-11-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Node | >=22 |
| Dependencies | 1 |
| Unpacked size | 11 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| Author | Leo Pradel |
| Maintainers | leopradel |
| Keywords | bundle, esbuild, esbuild-plugin, node_modules |

## Links

- npm: https://www.npmjs.com/package/esbuild-node-externals
- Repository: https://github.com/pradel/esbuild-node-externals
- npm.io page: https://npm.io/package/esbuild-node-externals

## Dependencies (1)

- [empathic](https://npm.io/package/empathic.md) ^2.0.0

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2026-08-04
- 1.23.1 — 2026-06-13
- 1.22.0 — 2026-04-08
- 1.21.0 — 2026-04-03
- 1.20.1 — 2025-11-15
- 1.19.1 — 2025-11-11
- 1.18.0 — 2025-02-11
- 1.17.0 — 2025-02-11
- 1.16.0 — 2024-12-17
- 1.15.0 — 2024-09-26
- 1.14.0 — 2024-07-09
- 1.13.1 — 2024-05-07
- 1.13.0 — 2024-02-12
- 1.12.0 — 2023-12-20
- 1.11.0 — 2023-11-20
- … 15 more at https://npm.io/package/esbuild-node-externals/versions

## README

# esbuild-node-externals

[![npm version](https://img.shields.io/npm/v/esbuild-node-externals.svg)](https://www.npmjs.com/package/esbuild-node-externals)
[![npm downloads per month](https://img.shields.io/npm/dm/esbuild-node-externals.svg)](https://www.npmjs.com/package/esbuild-node-externals)

[Esbuild](https://github.com/evanw/esbuild) plugin to easily exclude node modules during builds.

When bundling with Esbuild for the backend by default it will try to bundle all the dependencies. However it's a good idea to not bundle all the `node_modules` dependencies. This plugin will scan the dependencies included in your project and will exclude them from the final bundle.

## Installation

This plugin requires minimum **Node.js 12**, and **Esbuild 0.12+**.

```sh
# with npm
npm install --save-dev esbuild-node-externals

# with pnpm
pnpm add -D esbuild-node-externals

# with yarn
yarn add -D esbuild-node-externals
```

## Usage

When you call the esbuild build API, add the esbuild-node-externals plugin.

```js
// Your bundler file
const esbuild = require('esbuild');
const { nodeExternalsPlugin } = require('esbuild-node-externals');

esbuild.build({
  entryPoints: ['src/index.js'],
  bundle: true,
  platform: 'node',
  outfile: 'dist/index.js',
  plugins: [nodeExternalsPlugin()],
});
```

## Options

When calling this package, you can pass an `options` object.

```js
// Your bundler file
const esbuild = require('esbuild');
const { nodeExternalsPlugin } = require('esbuild-node-externals');

esbuild.build({
  // ...
  plugins: [
    nodeExternalsPlugin({
      packagePath: 'path/to/package.json',
    }),
  ],
});
```

#### `options.packagePath`

Path to your `package.json`. Can be a string or an array of strings. If you are using a monorepo you can provide a list of all the `package.json` to check.

If this option is not specified the default behavior is to start with the current directory's package.json then go up scan for all package.json files in parent directories recursively until either the root git directory is reached or until no other package.json can be found.

#### `options.dependencies` (default to `true`)

Make package.json `dependencies` external.

#### `options.devDependencies` (default to `true`)

Make package.json `devDependencies` external.

#### `options.peerDependencies` (default to `true`)

Make package.json `peerDependencies` external.

#### `options.optionalDependencies` (default to `true`)

Make package.json `optionalDependencies` external.

#### `options.allowList` (default to `[]`)

An array for the externals to allow, so they will be included in the bundle. Can accept exact strings ('module_name'), regex patterns (/^module_name/), or a function that accepts the module name and returns whether it should be included.

#### `options.forceExternalList` (default to `[]`)

An array that forces packages to be treated as external, even if not in `package.json`, so they will be excluded from the bundle. Can accept exact strings ('module_name'), regex patterns (/^module_name/), or a function that accepts the module name and returns whether it should be externalized.

#### `options.allowWorkspaces` (default to `false`)

Automatically exclude all packages defined as workspaces (`workspace:*`) in a monorepo.

#### `options.cwd` (default to `buildOptions.absWorkingDir || process.cwd()`)

Sets the current working directory for the plugin.

## Inspiration

This package and the implementation are inspired by the work of @liady on [webpack-node-externals](https://github.com/liady/webpack-node-externals) for webpack and @Septh on [rollup-plugin-node-externals](https://github.com/Septh/rollup-plugin-node-externals) for rollup.

## License

MIT © [Léo Pradel](https://www.leopradel.com/)

---
_Source: https://npm.io/package/esbuild-node-externals · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
