Skip to content
Latchkey

npm "EBADPLATFORM" - Fix Wrong OS/CPU for a Package in CI

npm refused to install a package because its os/cpu/libc fields do not match the current runner. The package is platform-specific and you are on the wrong platform - common with committed lockfiles that pin a different OS’s binary.

What this error means

npm install/npm ci aborts with EBADPLATFORM, printing what the package wanted (e.g. darwin/arm64) versus the current platform (linux/x64). It often surfaces when a lockfile generated on a Mac is installed on a Linux runner.

npm output
npm error code EBADPLATFORM
npm error notsup Unsupported platform for fsevents@2.3.3:
wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

Common causes

A platform-specific dependency on the wrong OS/arch

A package declares os/cpu constraints (e.g. fsevents is macOS-only). Installing it on a different platform trips EBADPLATFORM.

Lockfile pins a foreign-platform optional binary

A lockfile generated on one OS can hard-pin a platform-specific optional dependency; installing it on another OS fails instead of selecting that platform’s variant.

How to fix it

Let optional platform deps resolve per platform

Platform-specific packages are usually optionalDependencies. Regenerate the lockfile so npm records each platform’s variant, and avoid forcing a single OS’s binary.

Terminal
# regenerate so optional platform deps resolve correctly
rm package-lock.json
npm install
git add package-lock.json

Match the runner to the package, or skip optional

  1. If the package is truly required, run on the platform it supports.
  2. For optional native deps, install with optional deps enabled so the wrong-platform one is skipped, not fatal.
  3. Use os/cpu-aware tooling (modern npm) that selects the right binary per runner.

How to prevent it

  • Generate the lockfile in an environment matching CI, or commit a multi-platform lockfile (npm 9+).
  • Keep platform-specific packages as optional dependencies.
  • Run native-dependent jobs on the OS/arch the packages support.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →