How to fix npm ERR! code ELIFECYCLE npm ERR! package@version postinstall: `node script.js` npm ERR! Exit status 1 npm ERR! Failed at the package@version postinstall script in npm
Postinstall script failures occur when a package's setup script fails after download. Common causes include missing build tools, permission issues, or network problems downloading binaries.
Quick fix
Fixes npm ERR! code ELIFECYCLE npm ERR! package@version postinstall: `node script.js` npm ERR! Exit status 1 npm ERR! Failed at the package@version postinstall script
# Common errors you might see:
gyp ERR! find Python
gyp ERR! find VS # Visual Studio on Windows
node-pre-gyp ERR! Tried to download(404): ...
EACCES: permission denied- Read the actual error above ELIFECYCLE
- Install required build tools
- Clean cache and reinstall
- Run with unsafe-perm for permission issues
# Common errors you might see:gyp ERR! find Pythongyp ERR! find VS # Visual Studio on Windowsnode-pre-gyp ERR! Tried to download(404): ...EACCES: permission deniednpm ERR! code ELIFECYCLEnpm ERR! package@version postinstall: `node script.js`npm ERR! Exit status 1npm ERR! Failed at the package@version postinstall script
What this error means
The "Failed at postinstall script" error occurs when a package's postinstall hook—a script that runs automatically after the package is downloaded—exits with a non-zero status. Many packages use postinstall to compile native modules, download platform-specific binaries, or perform setup tasks. The error message "This is probably not a problem with npm" is actually accurate—the failure is in the package's postinstall script, not npm itself. The real error is in the output above the ELIFECYCLE message. Common culprits include node-sass, Electron, bcrypt, and packages that compile C++ code.
Typical symptoms
- npm install fails during postinstall phase
- Error shows specific package name and "postinstall script" failure
- CI/CD pipelines fail with no detailed error before ELIFECYCLE
- Works on macOS but fails on Windows/Linux or vice versa
- npm install hangs then fails mid-way through
- Binaries in node_modules/.bin missing after install
Common causes
- Missing build tools (Python, C++ compiler, make)
- Permission denied when creating files/directories
- Network issues downloading pre-built binaries
- Node.js version incompatible with package
- Corrupted npm cache
- Proxy/firewall blocking binary downloads
- Resource exhaustion (memory, disk space)
How to fix "npm ERR! code ELIFECYCLE npm ERR! package@version postinstall: `node script.js` npm ERR! Exit status 1 npm ERR! Failed at the package@version postinstall script"
Scroll up in terminal output to find the real error:
# Common errors you might see:
gyp ERR! find Python
gyp ERR! find VS # Visual Studio on Windows
node-pre-gyp ERR! Tried to download(404): ...
EACCES: permission deniedThe error above tells you exactly what postinstall script failed to do.
Many postinstall scripts need compilation tools:
macOS:
xcode-select --installWindows:
npm install -g windows-build-tools
# Or install Visual Studio Build Tools manuallyUbuntu/Debian:
sudo apt-get install build-essential python3Alpine Docker:
RUN apk add --no-cache python3 make g++Clear corrupted cache state:
# Clean npm cache
npm cache clean --force
# Remove node_modules and lock file
rm -rf node_modules package-lock.json
# Reinstall
npm installIf the error is permission-related:
# Allow postinstall scripts to run as root
npm install --unsafe-perm
# Or set globally
npm config set unsafe-perm trueThis is often needed in Docker containers running as root.
npm ci is stricter and more reliable for CI:
# Clean install respecting exact lock file versions
npm cinpm ci deletes node_modules first and installs exact versions from package-lock.json.
See what the postinstall script is doing:
# npm 7+: Run scripts in foreground for visibility
npm install --foreground-scripts
# Or set log level for more detail
npm install --loglevel verboseIsolate the problematic package:
# Install without running scripts
npm install --ignore-scripts
# Then manually run postinstall for specific package
cd node_modules/problematic-package
node scripts/postinstall.jsThis helps identify which package is failing.
Advanced notes
Common postinstall failure packages and their fixes:
node-sass: Deprecated. Replace with sass (Dart Sass):
npm uninstall node-sass && npm install sassElectron: Needs specific environment variables for downloads:
export ELECTRON_MIRROR="https://npmmirror.com/mirrors/electron/"bcrypt: Use bcryptjs (pure JS) if native compilation fails:
npm uninstall bcrypt && npm install bcryptjsFor corporate proxies blocking downloads, configure npm:
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080Frequently asked questions
- What does "npm ERR! code ELIFECYCLE npm ERR! package@version postinstall: `node s" mean?
- The "Failed at postinstall script" error occurs when a package's postinstall hook—a script that runs automatically after the package is downloaded—exits with a non-zero status. Many packages use postinstall to compile native modules, download platform-specific binaries, or perform setup tasks. The error message "This is probably not a problem with npm" is actually accurate—the failure is in the package's postinstall script, not npm itself.
- How do I fix "npm ERR! code ELIFECYCLE npm ERR! package@version postinstall: `node s"?
- Postinstall script failures occur when a package's setup script fails after download. Common causes include missing build tools, permission issues, or network problems downloading binaries.
- What causes "npm ERR! code ELIFECYCLE npm ERR! package@version postinstall: `node s"?
- Missing build tools (Python, C++ compiler, make) Permission denied when creating files/directories Network issues downloading pre-built binaries
- Is the "npm ERR! code ELIFECYCLE npm ERR! package@version postinstall: `node s" error serious?
- It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.