npm node-gyp Build Failed in CI - Fix Native Addon Compilation
node-gyp compiles native addons from source when no prebuilt binary is available. The build needs a C/C++ toolchain and Python, and it fails when those are missing on the runner.
What this error means
During install a package with native code fails with gyp ERR! build error and a make or compiler error. It often appears only in CI because the local machine already has build tools installed.
npm
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit
gyp ERR! System Linux
npm ERR! code 1Common causes
No compiler toolchain on the runner
node-gyp needs gcc/g++/make (build-essential) to compile the addon, and a minimal image often lacks them.
Missing or wrong Python
node-gyp drives the build through Python; an absent or incompatible Python breaks configuration before compilation.
How to fix it
Install the build toolchain
- Install build-essential and python3 before npm install.
- Re-run the install so node-gyp can compile.
Terminal
sudo apt-get update
sudo apt-get install -y build-essential python3
npm ciPrefer a prebuilt binary when available
- Pin a package version that ships prebuilt binaries for your platform.
- This avoids compiling from source entirely.
How to prevent it
- Use a runner image that already includes a C/C++ toolchain and Python, or install them in a cached setup step, so native addons compile reliably.
Related guides
node-gyp "gyp ERR! build error" - Fix Native Module Compilation in CIFix node-gyp "gyp ERR! build error" in CI - native addon compilation failing due to a missing compiler toolch…
node-gyp "Could not find any Python installation" - Fix Native Builds in CIFix node-gyp "Could not find any Python installation to use" in CI - native addon builds need Python; install…
npm ELIFECYCLE Error in CI - Diagnose Failing Lifecycle ScriptsFix "npm ERR! code ELIFECYCLE" during install in CI by finding the lifecycle script that exited non-zero and…