How to fix npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! package@version install: `node-gyp rebuild` npm ERR! Exit status 1 npm ERR! Failed at the package@version install script in npm

npmINTERMEDIATEHIGHUpdated Dec 6, 2025ยท 153 views

The node-gyp rebuild error occurs when npm can't compile native C/C++ modules. Install build tools (Python, make, g++) for your platform, or use pre-built binaries when available.

Quick fix

Fixes ELIFECYCLE

xcode-select --install
  1. Install build tools on macOS
  2. Install build tools on Ubuntu/Debian
  3. Install build tools on Windows
  4. Configure Python for node-gyp
npm โ€” error
xcode-select --install
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! package@version install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! Failed at the package@version install script

What this error means

This error occurs when npm tries to compile a native Node.js addon (written in C/C++) and the compilation fails. Packages like bcrypt, canvas, sqlite3, and sharp include native code that must be compiled for your specific platform. node-gyp is the tool that handles this compilation. It needs: - Python (for build scripts) - A C++ compiler (g++, clang, or Visual Studio) - make (on Unix) or msbuild (on Windows) If any of these are missing or misconfigured, the build fails with ELIFECYCLE.

Typical symptoms

  • npm install fails with 'gyp ERR! build error'
  • Error mentions node-gyp rebuild
  • Compilation errors for C/C++ code
  • Works on some machines but not others
  • Python not found errors
  • Visual Studio or compiler not found
  • Fails specifically on packages like bcrypt, canvas, sqlite3

Common causes

  1. Missing C++ compiler (g++, Visual Studio)
  2. Python not installed or wrong version
  3. Build tools not in PATH
  4. node-gyp version incompatible with Node.js version
  5. Missing system libraries the native code depends on
  6. Permission issues accessing build directories
  7. Insufficient disk space for compilation

How to fix "npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! package@version install: `node-gyp rebuild` npm ERR! Exit status 1 npm ERR! Failed at the package@version install script"

1Install build tools on macOS

Install Xcode Command Line Tools:

bash
xcode-select --install

This provides the C++ compiler (clang) and other build essentials.

2Install build tools on Ubuntu/Debian

Install the build-essential package:

bash
sudo apt-get update
sudo apt-get install build-essential g++ make python3

For some packages, you may need additional libraries:

bash
sudo apt-get install libcairo2-dev libjpeg-dev libpango1.0-dev libgif-dev
3Install build tools on Windows

Option 1 - Use npm to install build tools:

powershell
npm install --global windows-build-tools

Option 2 - Manual installation:
1. Install Visual Studio 2022
2. Select "Desktop development with C++" workload
3. Install Python 3.x from python.org
4. Restart your terminal

4Configure Python for node-gyp

Tell npm which Python to use:

bash
npm config set python /usr/bin/python3

Or on Windows:

powershell
npm config set python C:\Python39\python.exe
5Update node-gyp

Use the latest node-gyp:

bash
npm install -g node-gyp@latest

Then retry your installation.

6Use pre-built binaries when available

Some packages offer pre-built binaries to avoid compilation:

bash
# For bcrypt, use bcryptjs (pure JavaScript)
npm uninstall bcrypt
npm install bcryptjs

# For sqlite3, pre-built binaries are usually available
npm install sqlite3 --build-from-source=false

Check the package documentation for alternatives.

Advanced notes

For Docker containers, install build dependencies in your Dockerfile:

dockerfile
FROM node:20

# Install build dependencies
RUN apt-get update && apt-get install -y \
    build-essential \
    python3 \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app
COPY package*.json ./
RUN npm ci

For Alpine Linux (common in Docker), you need different packages:

dockerfile
FROM node:20-alpine
RUN apk add --no-cache python3 make g++

If you're on an M1/M2 Mac and having issues with x86 packages, try:

bash
arch -x86_64 npm install

Or rebuild the package for ARM:

bash
npm rebuild

Frequently asked questions

What does "ELIFECYCLE" mean?
js addon (written in C/C++) and the compilation fails. Packages like bcrypt, canvas, sqlite3, and sharp include native code that must be compiled for your specific platform. node-gyp is the tool that handles this compilation.
How do I fix "ELIFECYCLE"?
The node-gyp rebuild error occurs when npm can't compile native C/C++ modules. Install build tools (Python, make, g++) for your platform, or use pre-built binaries when available.
What causes "ELIFECYCLE"?
Missing C++ compiler (g++, Visual Studio) Python not installed or wrong version Build tools not in PATH
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