How to fix npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! [script] exited with code 1 in Node.js

Node.jsBEGINNERMEDIUMUpdated Dec 9, 2025· 169 views

The ELIFECYCLE error occurs when an npm script defined in package.json fails during execution and exits with a non-zero status code. This is a wrapper error that indicates the underlying script command encountered a problem.

Quick fix

Fixes ELIFECYCLE

# Clear npm cache
npm cache clean --force

# Remove node_modules and lock file
rm -rf node_modules package-lock.json

# Reinstall all dependencies
npm install
  1. Read the complete error output above ELIFECYCLE
  2. Clean npm cache and reinstall dependencies
  3. Verify Node.js and npm versions
  4. Check package.json scripts for errors
node.js — error
# Clear npm cache
npm cache clean --force
# Remove node_modules and lock file
rm -rf node_modules package-lock.json
# Reinstall all dependencies
npm install
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [script] exited with code 1

What this error means

The ELIFECYCLE error is npm's way of reporting that a lifecycle script (such as start, build, test, or any custom script) has failed to complete successfully. The error itself is not the root cause—it's a signal that the command executed by the script encountered an issue and returned a non-zero exit code. When a process exits with code 0, it indicates success. Any other exit code (1, 127, etc.) signals an error condition. The ELIFECYCLE error wraps this exit code and provides additional context about which script failed. The actual problem is usually found in the error output that appears above the ELIFECYCLE message. Common exit codes include 1 (general error), 127 (command not found), and 126 (command not executable). Understanding these codes helps identify whether the issue is a missing dependency, syntax error, or configuration problem.

Typical symptoms

  • npm run commands fail with ELIFECYCLE error message
  • Error appears after attempting to run npm start, npm test, or npm run build
  • Error output includes "npm ERR! errno" followed by a number
  • Build or deployment pipelines fail at the npm script execution step
  • Scripts that previously worked now fail after dependency updates
  • Error messages about missing commands or modules appear above ELIFECYCLE

Common causes

  1. The underlying script command has a syntax error or runtime exception
  2. Required dependencies are missing or not properly installed in node_modules
  3. Node.js or npm version incompatibility with project requirements
  4. Corrupted npm cache causing module resolution issues
  5. Script references a command that is not installed or not in PATH
  6. Environment variables required by the script are not set
  7. Peer dependency conflicts between installed packages
  8. File permissions prevent script execution or file access
  9. Memory or disk space limitations during script execution

How to fix "npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! [script] exited with code 1"

1Read the complete error output above ELIFECYCLE

The ELIFECYCLE error is always preceded by the actual error that caused the script to fail. Scroll up in your terminal to find the real error message.

Look for messages that appear before the ELIFECYCLE error:
- Module not found errors
- Syntax errors in your code
- Command not found messages
- Runtime exceptions from your application

The ELIFECYCLE error is just npm's way of saying "your script failed"—the details above it tell you why.

2Clean npm cache and reinstall dependencies

Corrupted cache or incomplete installations often cause script failures. Clean everything and start fresh:

bash
# Clear npm cache
npm cache clean --force

# Remove node_modules and lock file
rm -rf node_modules package-lock.json

# Reinstall all dependencies
npm install

On Windows, use:

cmd
rmdir /s /q node_modules
del package-lock.json
npm install

This ensures all dependencies are correctly installed with fresh metadata.

3Verify Node.js and npm versions

Version mismatches between your environment and project requirements often cause script failures:

bash
# Check current versions
node --version
npm --version

# Check required versions in package.json
cat package.json | grep -A 2 "engines"

If your package.json specifies engine requirements:

json
{
  "engines": {
    "node": ">=18.0.0",
    "npm": ">=9.0.0"
  }
}

Update Node.js using nvm (Node Version Manager):

bash
# Install nvm if needed, then:
nvm install 18
nvm use 18

Or download the appropriate version from nodejs.org.

4Check package.json scripts for errors

Review the script definition in package.json for typos, incorrect paths, or missing commands:

json
{
  "scripts": {
    "start": "node server.js",
    "build": "webpack --config webpack.config.js",
    "test": "jest"
  }
}

Common issues to look for:
- Typos in command names (e.g., "ndoe" instead of "node")
- References to files that don't exist
- Commands from dev dependencies when running in production
- Incorrect flag syntax

Test the command manually to verify it works:

bash
# If your script is: "start": "node server.js"
# Run it directly:
node server.js
5Run the script with verbose logging

Enable detailed output to see exactly where and why the script fails:

bash
# Run with verbose logging
npm run build --verbose

# Or with even more detail
npm run build --loglevel silly

The verbose output shows:
- Exact commands being executed
- Environment variables in use
- Module resolution paths
- Timing information for each step

This additional context often reveals the specific point of failure that the standard error output doesn't show.

6Verify required dependencies are installed

If your script uses a specific tool or library, ensure it's installed:

bash
# List all top-level dependencies
npm ls --depth=0

# Check for a specific package
npm ls webpack

# Verify dev dependencies are installed (needed for build scripts)
npm install --include=dev

For exit code 127 (command not found), install the missing command:

bash
# If the script uses a tool like webpack or typescript:
npm install --save-dev webpack webpack-cli
# or
npm install --save-dev typescript ts-node

Make sure the command is accessible in node_modules/.bin or installed globally if needed.

7Handle peer dependency conflicts

Peer dependency conflicts can cause scripts to fail, especially after updates:

bash
# Check for peer dependency warnings
npm install

# If you see peer dependency errors, try legacy mode
npm install --legacy-peer-deps

# Or force resolution (use with caution)
npm install --force

The --legacy-peer-deps flag tells npm to use the legacy (npm 6 and below) peer dependency resolution behavior, which can resolve conflicts in some cases.

Note: Using --force can lead to broken dependencies. Only use it if you understand the implications and plan to test thoroughly.

Advanced notes

Exit Code Reference:
- Exit code 1: General error (syntax error, runtime exception, assertion failure)
- Exit code 127: Command not found (binary not in PATH or not installed)
- Exit code 126: Command found but not executable (permission issue)
- Exit code 2: Misuse of shell command (incorrect usage)
- Exit code 130: Script terminated by Ctrl+C (SIGINT)

CI/CD Considerations:

In continuous integration environments, ELIFECYCLE errors often stem from environment differences:
- Missing environment variables that exist locally
- Different Node.js versions between local and CI
- Dev dependencies not installed in production builds
- File paths that work on one OS but fail on another

Always specify exact versions in package.json engines field and use the same Node.js version locally and in CI.

Memory and Resource Limits:

Large builds can fail with ELIFECYCLE if Node.js runs out of memory:

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

Or modify the script in package.json:

json
{
  "scripts": {
    "build": "node --max-old-space-size=4096 node_modules/.bin/webpack"
  }
}

Windows-Specific Issues:

Windows users may encounter ELIFECYCLE errors due to:
- Line ending differences (CRLF vs LF) in scripts
- Path separator differences (backslash vs forward slash)
- Long path limitations (260 character limit in older Windows versions)

Consider using cross-platform tools like cross-env for environment variables and cross-spawn for running commands.

Debugging with npm scripts:

You can add debug scripts to your package.json to troubleshoot:

json
{
  "scripts": {
    "debug:build": "node --inspect-brk node_modules/.bin/webpack",
    "prebuild": "echo 'Starting build...'",
    "postbuild": "echo 'Build completed!'"
  }
}

Pre and post hooks (prebuild, postbuild) can help identify which stage of your script is failing.

Frequently asked questions

What does "ELIFECYCLE" mean?
The ELIFECYCLE error is npm's way of reporting that a lifecycle script (such as start, build, test, or any custom script) has failed to complete successfully. The error itself is not the root cause—it's a signal that the command executed by the script encountered an issue and returned a non-zero exit code. When a process exits with code 0, it indicates success.
How do I fix "ELIFECYCLE"?
The ELIFECYCLE error occurs when an npm script defined in package.json fails during execution and exits with a non-zero status code. This is a wrapper error that indicates the underlying script command encountered a problem.
What causes "ELIFECYCLE"?
The underlying script command has a syntax error or runtime exception Required dependencies are missing or not properly installed in node_modules Node.js or npm version incompatibility with project requirements
Is the "ELIFECYCLE" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading