npm postinstall Script Failed in CI - Fix Failing postinstall Hooks
A postinstall script runs after a package is installed, often to compile native code, download a binary, or generate files. It fails in CI when its requirements are missing.
What this error means
npm install fails on a dependency postinstall step with a non-zero exit. The error names a build tool, a network download, or a codegen step that did not complete in the CI environment.
npm
> some-native-dep@3.0.0 postinstall
> node-gyp rebuild
gyp ERR! build error
npm ERR! code 1
npm ERR! some-native-dep@3.0.0 postinstall: `node-gyp rebuild`Common causes
A native build in postinstall lacks a toolchain
A postinstall that runs node-gyp needs a compiler and Python the runner does not have.
A postinstall download is blocked or times out
A hook that fetches a binary fails behind a proxy or on a flaky network.
How to fix it
Provide what the hook needs
- Read the postinstall command to see what it does.
- Install the missing toolchain or configure network access, then reinstall.
Terminal
sudo apt-get install -y build-essential python3
npm ciPrefer prebuilt binaries or skip when safe
- Pin a version that ships prebuilt binaries to avoid the build.
- Only use --ignore-scripts if you understand which postinstalls you are skipping.
How to prevent it
- Use runner images with the toolchains your dependencies need, prefer packages with prebuilt binaries. For postinstalls that download over the network, Latchkey managed runners auto-retry transient fetch failures and cache the registry.
Related guides
npm --ignore-scripts - postinstall Skipped, Native Binary MissingFix breakage from npm --ignore-scripts in CI - packages that rely on postinstall (native builds, binary downl…
npm node-gyp Build Failed in CI - Fix Native Addon CompilationFix "gyp ERR! build error" / node-gyp build failures in CI by installing the C/C++ toolchain and Python that…
husky / prepare Script Fails in CI - Fix Git Hook Install in CIFix husky prepare-script failures in CI, caused by husky trying to install Git hooks where there is no .git d…