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
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- Install build tools on macOS
- Install build tools on Ubuntu/Debian
- Install build tools on Windows
- Configure Python for node-gyp
xcode-select --installnpm ERR! code ELIFECYCLEnpm ERR! errno 1npm ERR! package@version install: `node-gyp rebuild`npm ERR! Exit status 1npm 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
- Missing C++ compiler (g++, Visual Studio)
- Python not installed or wrong version
- Build tools not in PATH
- node-gyp version incompatible with Node.js version
- Missing system libraries the native code depends on
- Permission issues accessing build directories
- 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"
Install Xcode Command Line Tools:
xcode-select --installThis provides the C++ compiler (clang) and other build essentials.
Install the build-essential package:
sudo apt-get update
sudo apt-get install build-essential g++ make python3For some packages, you may need additional libraries:
sudo apt-get install libcairo2-dev libjpeg-dev libpango1.0-dev libgif-devOption 1 - Use npm to install build tools:
npm install --global windows-build-toolsOption 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
Tell npm which Python to use:
npm config set python /usr/bin/python3Or on Windows:
npm config set python C:\Python39\python.exeUse the latest node-gyp:
npm install -g node-gyp@latestThen retry your installation.
Some packages offer pre-built binaries to avoid compilation:
# 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=falseCheck the package documentation for alternatives.
Advanced notes
For Docker containers, install build dependencies in your 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 ciFor Alpine Linux (common in Docker), you need different packages:
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:
arch -x86_64 npm installOr rebuild the package for ARM:
npm rebuildFrequently 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
- ๐npm Official Documentation
- ๐
- ๐ฌStack Overflow: npm install fails with node gyp(Stack Overflow)
- ๐