How to fix npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! package@version preinstall: `node script.js` npm ERR! Exit status 1 npm ERR! Failed at the package@version preinstall script in npm

npmINTERMEDIATEHIGHUpdated Dec 6, 2025ยท 126 views

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.

Quick fix

Fixes ELIFECYCLE

EACCES: permission denied, mkdir '/path/to/dir'
  1. Check the actual error message
  2. Fix npm permissions (recommended)
  3. Install build dependencies
  4. Clear cache and reinstall
npm โ€” error
EACCES: permission denied, mkdir '/path/to/dir'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! package@version preinstall: `node script.js`
npm ERR! Exit status 1
npm ERR! Failed at the package@version preinstall script

What this error means

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).

Typical symptoms

  • npm install fails immediately, before downloading packages
  • Error shows 'preinstall' in the script name
  • Permission denied errors in the output
  • Works with sudo but fails without (not recommended)
  • node-pre-gyp errors during preinstall
  • Prisma or similar ORMs fail at preinstall step

Common causes

  1. Permission denied creating build directories
  2. Missing build tools (Python, make, g++)
  3. npm running with wrong user permissions
  4. Insufficient memory for compilation (exit code 137)
  5. Network issues downloading prebuilt binaries
  6. Corrupted npm cache

How to fix "npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! package@version preinstall: `node script.js` npm ERR! Exit status 1 npm ERR! Failed at the package@version preinstall script"

1Check the actual error message

The real error is above ELIFECYCLE. Look for:

bash
EACCES: permission denied, mkdir '/path/to/dir'

or

bash
gyp ERR! find Python

This tells you exactly what to fix.

2Fix npm permissions (recommended)

Don't use sudo with npm. Instead, fix the directory ownership:

bash
# 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.

3Install build dependencies

If the error mentions gyp or native compilation:

macOS:

bash
xcode-select --install

Ubuntu/Debian:

bash
sudo apt-get install build-essential python3

Windows:

powershell
npm install -g windows-build-tools
4Clear cache and reinstall

Sometimes cached data causes preinstall failures:

bash
npm cache clean --force
rm -rf node_modules package-lock.json
npm install
5Skip preinstall scripts (temporary workaround)

If you need to proceed urgently:

bash
npm install --ignore-scripts

Warning: This skips all lifecycle scripts. Some packages won't work correctly without their scripts running. Only use for debugging.

6Check memory constraints

Exit code 137 indicates out-of-memory:

bash
# Increase Node.js memory limit
export NODE_OPTIONS="--max-old-space-size=4096"
npm install

For Docker, increase container memory allocation in docker-compose.yml or Docker Desktop settings.

Advanced notes

The --unsafe-perm flag allows npm to run scripts as root when installed with sudo, but this is a security risk:

bash
# Not recommended for general use
npm install --unsafe-perm

Only 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:

bash
# Generate Prisma client manually after install
npm install --ignore-scripts
npx prisma generate

If 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.

Frequently asked questions

What does "ELIFECYCLE" mean?
Preinstall scripts run before npm installs any dependencies. When a preinstall script fails, the entire installation is blocked at the very beginning. 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).
How do I fix "ELIFECYCLE"?
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.
What causes "ELIFECYCLE"?
Permission denied creating build directories Missing build tools (Python, make, g++) npm running with wrong user permissions
Is the "ELIFECYCLE" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading