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.
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.
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.
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:8080npm notice access token expired or revoked. Please try logging in again.
Token has expired - npm authentication failure
npm ERR! code EAI_AGAIN
How to fix "EAI_AGAIN" in npm
npm error code E403 npm error 403 Forbidden - PUT https://registry.npmjs.org/<package>
How to fix 'E403 Forbidden' error in npm
npm ERR! code EUSAGE npm ERR! Usage error
How to fix "npm ERR! code EUSAGE" in Node.js projects
npm ERR! code E401 npm ERR! 401 Unauthorized
How to fix "E401 Unauthorized" in npm