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