Skip to main content
TypeScript & Node.js · Developer Error Resolution Lab

Fix 'gyp ERR! build error' and 'node-gyp rebuild failed' (bcrypt, sharp, sqlite3, canvas)

Install the native build toolchain (Python, make, C++ compiler) or switch to prebuilt / pure-JS alternatives to stop node-gyp failures.

Triggered Error Message:

gyp ERR! build error gyp ERR! stack Error: `make` failed with exit code: 2 npm ERR! code 1 npm ERR! command sh -c node-gyp rebuild

Customize Solution for Your Environment
# Install the native toolchain for ubuntu
sudo apt-get install -y python3 make g++ build-essential

# Clean and reinstall
rm -rf node_modules package-lock.json
npm install

# Prefer prebuilt / pure-JS packages when possible:
#   bcrypt  -> bcryptjs
#   sqlite3 -> better-sqlite3 (prebuilt) or node:sqlite (Node 22+)

Root Cause & Mechanism Analysis

Why does this error occur?

A dependency ships native C/C++ addons and no prebuilt binary matches your Node.js version, OS, or CPU architecture, so npm compiles it from source. Compilation fails when Python 3, make, or a C++ compiler is missing, or when the package does not support your Node major version yet.

Frequently Asked Questions

Why does it work locally but fail in Docker?
Your machine has build tools and a prebuilt binary cache; slim/alpine images do not. Use a multi-stage build with the toolchain only in the build stage.
DEVSECOPS & CI/CD PARTNER2 Slots Open

Need Zero-Knowledge .env Secret Sync Across Your Engineering Team?

Explore Castov Env Vault for client-side AES-256-GCM encrypted environment sharing, or sponsor this engineering hub.

Browse All 69 Guides