esbuild macOS 64-bit Binary
esbuild is an extremely fast, next-generation JavaScript and CSS bundler and minifier, written in Go. This `esbuild-darwin-64` package provides the specific macOS 64-bit binary, acting as a platform-specific dependency for the main `esbuild` package. The project is actively maintained with frequent releases, currently at stable version `0.28.0`. Key differentiators include its exceptional speed, achieved through parallel parsing, printing, and source map generation, and its robust API for both JavaScript and Go. It supports ES6 and CommonJS modules, TypeScript, JSX, source maps, and minification, making it a versatile tool for modern web development.
Common errors
-
Error: Cannot find module 'esbuild'
cause The `esbuild` package is not installed, or the Node.js process cannot resolve it.fixRun `npm install esbuild` or `yarn add esbuild` in your project directory. Ensure `esbuild` is listed in your `package.json` dependencies. -
Error: Build failed: [ERROR] Could not resolve "./my-module" (use "--resolve-extensions=.ts,.tsx,.js,.jsx,.json,.mjs,.cjs" to specify custom extensions)
cause esbuild couldn't find a module because of a missing or incorrect file extension, or an incorrect path.fixVerify the module path and extension. You might need to explicitly list common extensions in `resolveExtensions` option, or ensure your `tsconfig.json` paths are correctly configured if using TypeScript aliases. -
Error: The "format" option must be either "cjs" or "esm" when "platform" is "node"
cause When targeting `platform: 'node'`, esbuild requires an explicit `format` option of either `'cjs'` (CommonJS) or `'esm'` (ES Modules) to disambiguate module output.fixAdd `format: 'cjs'` or `format: 'esm'` to your esbuild `build` options. Choose based on whether your Node.js project is CommonJS or ES Module-based. -
ReferenceError: require is not defined (when using CJS in an ESM context or vice-versa)
cause Attempting to use CommonJS `require` syntax in an ES Module context, or ESM `import` in a pure CommonJS context, often due to mismatched `type` in `package.json` or incorrect `format` in esbuild config.fixEnsure your `package.json` `type` field matches your intended module system (e.g., `"type": "module"` for ESM). In your esbuild config, set `format: 'esm'` or `format: 'cjs'` to match your target environment. For Node.js, also consider `platform: 'node'`.
Warnings
- breaking esbuild `0.27.0` included deliberate backwards-incompatible changes. Users should pin exact versions or use tilde/caret ranges (e.g., `^0.26.0` or `~0.26.0`) to avoid automatically picking up breaking changes.
- breaking As of `esbuild@0.28.0`, integrity checks for fallback binary downloads were added. While intended as an improvement, it was released as a breaking change due to embedding hashes of platform-specific binaries into the top-level `esbuild` package. This also involved an upgrade of the Go compiler from 1.25.7 to 1.26.1, which might introduce subtle behavioral changes in edge cases related to garbage collection and memory allocation.
- gotcha esbuild's TypeScript loader performs transpilation but does *not* do type-checking. For type-checking, you should run `tsc` separately or use a tool like `fork-ts-checker-webpack-plugin` if integrating with Webpack.
- gotcha Using `import()` expressions in non-ESM output formats (e.g., `cjs`) was previously transformed by esbuild, but `0.27.0` changed this behavior to preserve `import()` expressions. This means `import()` with Node.js is now possible when the output is not ESM, but requires the environment to handle these expressions.
- breaking The `0.27.2` release, while not explicitly marked as a breaking change in its summary, introduced a change where `using` declarations inside `switch` clauses, previously supported by esbuild, now result in a syntax error. This aligns with a relaxation in the `package.json` spec for import path specifiers starting with `#/`.
Install
-
npm install esbuild-darwin-64 -
yarn add esbuild-darwin-64 -
pnpm add esbuild-darwin-64
Imports
- build
const esbuild = require('esbuild'); esbuild.build({...})import { build } from 'esbuild' - BuildContext
import { BuildContext } from 'esbuild'import { context } from 'esbuild'; const ctx = await context({...}) - Plugin
import { Plugin } from 'esbuild'import type { Plugin } from 'esbuild'
Quickstart
import { build } from 'esbuild';
import path from 'path';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Create a dummy input file
import fs from 'fs';
const inputTs = `
interface User { id: number; name: string; }
const user: User = { id: 1, name: 'Alice' };
console.log(`Hello, ${user.name}!`);
export { user };
`;
const inputFilePath = path.join(__dirname, 'src', 'main.ts');
const outputDirPath = path.join(__dirname, 'dist');
fs.mkdirSync(path.join(__dirname, 'src'), { recursive: true });
fs.writeFileSync(inputFilePath, inputTs);
async function runBuild() {
try {
await build({
entryPoints: [inputFilePath],
bundle: true,
outdir: outputDirPath,
platform: 'node',
format: 'esm',
target: 'es2022',
minify: true,
sourcemap: true,
logLevel: 'info',
banner: { js: '// Built with esbuild' },
define: { 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV ?? 'development') },
});
console.log(`
Build successful! Output in: ${outputDirPath}`);
console.log('Generated file content:');
console.log(fs.readFileSync(path.join(outputDirPath, 'main.js'), 'utf-8'));
} catch (e) {
console.error('Build failed:', e);
process.exit(1);
}
}
runBuild();