Preinstall script failures block npm install before dependencies are even fetched. Common causes include permission issues, missing build tools, or memory constraints. Fix permissions or install required build dependencies.
Preinstall scripts run before npm installs any dependencies. When a preinstall script fails, the entire installation is blocked at the very beginning. Preinstall scripts are typically used for: - Checking prerequisites (Node.js version, system requirements) - Setting up native module compilation - Running security checks or validations The most common causes are permission errors (the script can't create directories or files) and missing build tools (the script tries to compile native code).
The real error is above ELIFECYCLE. Look for:
EACCES: permission denied, mkdir '/path/to/dir'or
gyp ERR! find PythonThis tells you exactly what to fix.
Don't use sudo with npm. Instead, fix the directory ownership:
# Check npm prefix
npm config get prefix
# If it's /usr/local, change ownership
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}Or better, use nvm to avoid permission issues entirely.
If the error mentions gyp or native compilation:
macOS:
xcode-select --installUbuntu/Debian:
sudo apt-get install build-essential python3Windows:
npm install -g windows-build-toolsSometimes cached data causes preinstall failures:
npm cache clean --force
rm -rf node_modules package-lock.json
npm installIf you need to proceed urgently:
npm install --ignore-scriptsWarning: This skips all lifecycle scripts. Some packages won't work correctly without their scripts running. Only use for debugging.
Exit code 137 indicates out-of-memory:
# Increase Node.js memory limit
export NODE_OPTIONS="--max-old-space-size=4096"
npm installFor Docker, increase container memory allocation in docker-compose.yml or Docker Desktop settings.
The --unsafe-perm flag allows npm to run scripts as root when installed with sudo, but this is a security risk:
# Not recommended for general use
npm install --unsafe-permOnly use this in controlled environments like CI/CD or Docker containers where you understand the implications.
For packages like Prisma that commonly have preinstall issues:
# Generate Prisma client manually after install
npm install --ignore-scripts
npx prisma generateIf you're using a CI system and preinstall fails with permission errors, ensure the CI user has write access to the workspace and npm directories.
npm ERR! code E401 npm ERR! 401 Unauthorized - Token has expired
Token has expired - npm authentication failure
npm ERR! code EAI_NODATA npm ERR! errno EAI_NODATA npm ERR! getaddrinfo EAI_NODATA registry.npmjs.org
How to fix "npm ERR! code EAI_NODATA - getaddrinfo EAI_NODATA"
npm ERR! code EMPTYPACKAGE npm ERR! Package contains no files
How to fix 'npm ERR! code EMPTYPACKAGE' - Package contains no files
npm ERR! code EWORKSPACEMISSING npm ERR! Workspace does not exist: packages/missing
How to fix "npm ERR! code EWORKSPACEMISSING - Workspace does not exist" error
npm ERR! code EADDRNOTAVAIL npm ERR! errno EADDRNOTAVAIL npm ERR! Address not available
How to fix "npm ERR! code EADDRNOTAVAIL - Address not available" error