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 showFix it fast
Most common cause, 1 of 4npm 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.
rm -rf node_modules
npm ci --include=optionalShort 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).
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.
node -p "process.platform + '-' + process.arch"
ls node_modules/@esbuild/Then find the line you see in this list and open its fix:
- 1npm was told to leave optional dependencies out
node_modules/@esbuild is empty, and the npm config or the install command contains omit=optional - 2package-lock.json only lists the binary of the machine that wrote it
Optional dependencies are on, yet node_modules/@esbuild stays empty, and package-lock.json has no entry for your platform's @esbuild package - 3node_modules was copied or mounted from another operating system
node_modules/@esbuild holds a linux-, darwin- or win32- folder that does not match what Node printed - 4On an Apple silicon Mac, npm and node ran under different architectures
The 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.
npm config ls -l | grep omit
env | grep -i npm_config_omitFix
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.
rm -rf node_modules
npm ci --include=optionalVerify
The folder for this platform now exists and the binary answers with its version.
ls node_modules/@esbuild/
npx esbuild --versionConfirmed by esbuild.github.io
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.
grep '"node_modules/@esbuild/' package-lock.jsonFix
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.
rm -rf node_modules package-lock.json
npm install
git add package-lock.jsonVerify
The grep now lists many @esbuild platform entries, including yours, and a clean install on the other machine runs esbuild.
grep -c '"node_modules/@esbuild/' package-lock.jsonConfirmed by github.com
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.
grep -n node_modules .dockerignoreFix
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.
# .dockerignore
node_modules
# Dockerfile
COPY package.json package-lock.json ./
RUN npm ci
COPY . .Verify
The image builds, and esbuild runs inside it.
docker build -t app:test . && docker run --rm app:test npx esbuild --versionConfirmed by esbuild.github.io
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.
node -p process.archFix
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.
node -p process.arch # should print arm64
rm -rf node_modules
npm ciVerify
node_modules/@esbuild contains darwin-arm64 only, and the build runs.
ls node_modules/@esbuild/ && npx esbuild --versionConfirmed by raw.githubusercontent.com
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.