esbuild

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

esbuild is an extremely fast JavaScript bundler and minifier written in Go. Current stable version is 0.21.x (as of this entry). It is released weekly with frequent bug fixes and features. Key differentiators include unmatched speed (10-100x faster than Webpack/Rollup), native Go implementation, built-in bundling, minification, TypeScript and JSX support, and a plugin API. It is designed for modern ESM and CJS workflows, and provides platform-specific binary packages like esbuild-openbsd-64-for-imba for easy installation.

error Error: Cannot find module 'esbuild'
cause esbuild is not installed or the platform-specific binary is missing.
fix
Run npm install esbuild (or yarn/pnpm equivalent). Ensure your node version is >=12.
error Error: The package 'esbuild' was built for a different platform.
cause The installed platform-specific binary does not match the current OS/architecture.
fix
Delete node_modules and reinstall. Use npm install esbuild --save-dev to install the correct binary automatically.
error TypeError: esbuild.build is not a function
cause Using `require('esbuild')` and calling `.build` directly without accessing the correct property in older versions.
fix
If using CommonJS, use const esbuild = require('esbuild'); esbuild.build(...). If using ESM, use import { build } from 'esbuild'.
breaking In v0.27.0, esbuild introduced backwards-incompatible changes. Pin exact version to avoid unexpected upgrades.
fix Use a version range like `^0.26.0` or `~0.26.0` in package.json, or pin to an exact version.
breaking In v0.26.0, esbuild enabled trusted publishing via GitHub Actions. If you rely on the old publishing method, update your workflows.
fix Ensure your CI/CD pipeline trusts the new publisher.
gotcha When using `require('esbuild')` in CommonJS, you must access `.build` etc. as properties; the default export is not a function.
fix Use `const esbuild = require('esbuild'); esbuild.build(...)` or switch to ESM imports.
deprecated The `startService` API is deprecated since v0.9.0 and removed in v0.13.0. Use `build` and `transform` directly.
fix Replace `startService` with direct calls to `build` and `transform`.
gotcha Platform-specific binaries (e.g., esbuild-openbsd-64-for-imba) are automatically downloaded by the main esbuild package. Manual installation is not needed and can cause version mismatches.
fix Install only `esbuild` as a dependency; do not add platform-specific packages directly.
npm install esbuild-openbsd-64-for-imba
yarn add esbuild-openbsd-64-for-imba
pnpm add esbuild-openbsd-64-for-imba

Shows basic bundling and minification with esbuild's build API using async/await.

import { build } from 'esbuild';

async function bundle() {
  try {
    const result = await build({
      entryPoints: ['src/index.js'],
      outfile: 'dist/bundle.js',
      bundle: true,
      minify: true,
      platform: 'browser',
      target: ['es2020'],
    });
    console.log('Build succeeded:', result);
  } catch (e) {
    console.error('Build failed:', e.message);
  }
}

bundle();