Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Next.js and React

esbuild cannot find its native binary for this Mac, Linux box or container

Your error

The package "@esbuild/darwin-arm64" could not be found, and is needed by esbuild.3 more lines it can show

Fix it fast

Most common cause, 1 of 4

npm was told to leave optional dependencies out

Remove optional from the omit setting wherever it was set, then install again. npm treats --include=optional as stronger than any omit entry, so it also works when you cannot edit a shared config.

Fix
rm -rf node_modules
npm ci --include=optional
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

The package "@esbuild/darwin-arm64" could not be found, and is needed by esbuild: npm never placed the native binary for this platform in node_modules. Optional dependencies were omitted, package-lock.json lists only another machine's binary, or node_modules came from another OS or Rosetta. Reinstall on the target machine with optional dependencies on (esbuild 0.28, npm 11 and 12).

  • Applies to esbuild 0.28.2, npm 12.2 and npm 11, macOS on Apple silicon, Linux x64 and arm64, Docker
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Print the platform Node runs as, then look inside node_modules/@esbuild. An empty or missing folder points to cause 1 or 2. A folder named for another platform, such as linux-x64 on a Mac or darwin-x64 on an arm64 Mac, points to cause 3 or 4.

Run this first
node -p "process.platform + '-' + process.arch"
ls node_modules/@esbuild/

Then find the line you see in this list and open its fix:

  1. 1npm was told to leave optional dependencies outnode_modules/@esbuild is empty, and the npm config or the install command contains omit=optional
  2. 2package-lock.json only lists the binary of the machine that wrote itOptional dependencies are on, yet node_modules/@esbuild stays empty, and package-lock.json has no entry for your platform's @esbuild package
  3. 3node_modules was copied or mounted from another operating systemnode_modules/@esbuild holds a linux-, darwin- or win32- folder that does not match what Node printed
  4. 4On an Apple silicon Mac, npm and node ran under different architecturesThe error says @esbuild/darwin-x64 is present but darwin-arm64 is needed (or the reverse), and mentions Rosetta 2

What does the error look like?

  • The package "@esbuild/darwin-arm64" could not be found, and is needed by esbuild.
  • If you are installing esbuild with npm, make sure that you don't specify the "--no-optional" or "--omit=optional" flags.
  • You installed esbuild for another platform than the one you're currently using.
  • Specifically the "@esbuild/darwin-x64" package is present but this platform needs the "@esbuild/darwin-arm64" package instead.

Cause 1 of 4

npm was told to leave optional dependencies out

You seenode_modules/@esbuild is empty, and the npm config or the install command contains omit=optional

Check

Every esbuild binary is published as its own optional package, so a run with optional dependencies omitted skips the one this machine needs and esbuild reports the package as not found. The omit value can come from a flag, an .npmrc file or an npm_config_omit environment variable, which is why the command in your script may look clean.

Check
npm config ls -l | grep omit
env | grep -i npm_config_omit

Fix

Remove optional from the omit setting wherever it was set, then install again. npm treats --include=optional as stronger than any omit entry, so it also works when you cannot edit a shared config.

Fix
rm -rf node_modules
npm ci --include=optional

Verify

The folder for this platform now exists and the binary answers with its version.

Verify
ls node_modules/@esbuild/
npx esbuild --version

Confirmed by esbuild.github.io

Did this fix it?

Cause 2 of 4

package-lock.json only lists the binary of the machine that wrote it

You seeOptional dependencies are on, yet node_modules/@esbuild stays empty, and package-lock.json has no entry for your platform's @esbuild package

Check

npm issue 4828 describes this: when the lockfile is regenerated while node_modules already exists, npm can keep only the platform package installed on that machine. A teammate or CI runner on another OS or CPU then installs from that lockfile and silently gets no binary.

Check
grep '"node_modules/@esbuild/' package-lock.json

Fix

Delete both node_modules and package-lock.json, run npm install, and commit the new lockfile. Deleting only one of the two does not repair it.

Fix
rm -rf node_modules package-lock.json
npm install
git add package-lock.json

Verify

The grep now lists many @esbuild platform entries, including yours, and a clean install on the other machine runs esbuild.

Verify
grep -c '"node_modules/@esbuild/' package-lock.json

Confirmed by github.com

Did this fix it?

Cause 3 of 4

node_modules was copied or mounted from another operating system

You seenode_modules/@esbuild holds a linux-, darwin- or win32- folder that does not match what Node printed

Check

esbuild's docs say an install from one OS cannot run on another, and name the usual routes: a node_modules folder from Windows or macOS copied into a Linux Docker image, or one shared between Windows and WSL. The binary that arrived belongs to the first system.

Check
grep -n node_modules .dockerignore

Fix

Keep the host's node_modules out of what you copy and install inside the target system. For Docker, list node_modules in .dockerignore and run npm ci in the Dockerfile; for WSL, run npm ci again inside WSL.

Fix
# .dockerignore
node_modules

# Dockerfile
COPY package.json package-lock.json ./
RUN npm ci
COPY . .

Verify

The image builds, and esbuild runs inside it.

Verify
docker build -t app:test . && docker run --rm app:test npx esbuild --version

Confirmed by esbuild.github.io

Did this fix it?

Cause 4 of 4

On an Apple silicon Mac, npm and node ran under different architectures

You seeThe error says @esbuild/darwin-x64 is present but darwin-arm64 is needed (or the reverse), and mentions Rosetta 2

Check

esbuild picks its binary from the architecture of the node process. An install done by an x86-64 node under Rosetta 2 fetches darwin-x64; running the project later with arm64 node then asks for darwin-arm64.

Check
node -p process.arch

Fix

Use one native arm64 Node for both installing and running, for example from the nodejs.org installer, then reinstall the project. esbuild's error text names that installer as one way out.

Fix
node -p process.arch   # should print arm64
rm -rf node_modules
npm ci

Verify

node_modules/@esbuild contains darwin-arm64 only, and the build runs.

Verify
ls node_modules/@esbuild/ && npx esbuild --version

Confirmed by raw.githubusercontent.com

Did this fix it?

How do I stop it coming back?

  • Commit package-lock.json only from a fresh install (no node_modules present) after dependency changes, so every platform entry stays in it.
  • Put node_modules in .dockerignore in every repo that builds an image.
  • Run npm ci in CI on each OS you ship to, which catches a lockfile that lost a platform entry before release.
  • Never use --omit=optional in projects that depend on esbuild, Vite or other tools with per-platform binaries.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: TaxiDex, Dispatch Pro.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.