LinuxCommandLibrary

npm-rebuild

rebuilds native addon modules for the current Node

TLDR

Rebuild all native modules

$ npm rebuild
copy
Rebuild specific package
$ npm rebuild [package]
copy
Rebuild for different Node version
$ npm rebuild --target=[18.0.0]
copy
Rebuild globally installed packages
$ npm rebuild -g
copy

SYNOPSIS

npm rebuild [options] [packages...]

DESCRIPTION

npm rebuild rebuilds native addon modules for the current Node.js version. This is necessary after upgrading Node.js or when native modules fail to load.
The command runs node-gyp rebuild for each package with native code.

PARAMETERS

-g, --global

Rebuild global packages.
--ignore-scripts
Don't run scripts.
--foreground-scripts
Run scripts in foreground.

COMMON USE CASES

$ # After Node.js upgrade
npm rebuild

# Fix broken native module
npm rebuild bcrypt

# Rebuild with verbose output
npm rebuild --verbose
copy

NATIVE MODULES

$ bcrypt, node-sass, sqlite3
sharp, canvas, grpc
leveldown, node-rdkafka
copy

CAVEATS

Requires build tools (Python, C++ compiler). May take significant time. Some modules need specific Node versions.

HISTORY

npm rebuild has been part of npm since early versions, essential for maintaining native addon compatibility across Node.js versions.

SEE ALSO

npm(1), npm-install(1), node-gyp(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community