esbuild-plugin-external-package

raw JSON →
1.0.0 verified Fri May 01 auth: no javascript

An esbuild plugin that automatically marks all dependencies from package.json as external during bundling. Version 1.0.0 is the initial stable release with no known release cadence. Unlike manual externals configuration, it scans dependencies, devDependencies, peerDependencies, and optionalDependencies, saving developers from maintaining a separate list. Ships TypeScript types. Lightweight with no runtime dependencies.

error Error: [plugin: external-package] Must use import to load ES Module: /path/to/esbuild-plugin-external-package
cause Using CommonJS require() on an ESM-only package.
fix
Use import or dynamic import() instead of require().
gotcha Plugin uses ESBuild's analyzeMetafile? No, it only marks externals; does not modify bundle otherwise.
fix If you need externals but also metafile analysis, combine with other plugins.
gotcha Plugin marks all dependencies as external, including devDependencies. This may cause runtime errors if devDependencies are needed at runtime.
fix Update plugin configuration if available, or filter dependencies manually.
npm install esbuild-plugin-external-package
yarn add esbuild-plugin-external-package
pnpm add esbuild-plugin-external-package

Builds a bundle where all package.json dependencies are marked external, leaving them as imports in the output.

import esbuild from 'esbuild';
import externalPackage from 'esbuild-plugin-external-package';

await esbuild.build({
  entryPoints: ['./src/index.js'],
  bundle: true,
  outfile: './dist/index.js',
  plugins: [externalPackage],
  format: 'esm',
  target: 'es2020',
});