FG
💻 Software🛠️ Developer ToolsMicrosoft

npm default install command always runs if binding.gyp exists, and package install script is ignored

Freshover 3 years ago
Mar 14, 20260 views
Confidence Score85%
85%

Problem

Is there an existing issue for this? - [X] I have searched the existing issues This issue exists in the latest npm version - [X] I am using the latest npm Current Behavior 1. use npm 7 or 8 2. package.json contains install script 3. project root directory contains binding.gyp 4. npm install results in default npm install command `node-gyp rebuild` running instead of the install script in package.json It works correctly with npm 6. Expected Behavior Expect it to behave as documented: > If there is a binding.gyp file in the root of your package and you haven't defined your own install or preinstall scripts, npm will default the install command to compile using node-gyp via node-gyp rebuild I assume this means: > If there is a binding.gyp file in the root of your package and you have defined your own install or preinstall scripts, npm will run your install and preinstall scripts and not default the install command to compile using node-gyp via node-gyp rebuild Steps To Reproduce 1. Create new directory with new package.json that has no dependencies 2. See canvas has binding.gyp and an install script in package.json. 3. npm i canvas@latest -S --verbose 4. "install": "node-pre-gyp install --fallback-to-build --update-binary", in canvas package.json is NOt run but should be 5. `npm info run canvas@2.9.3 install node_modules/canvas node-gyp rebuild` is run but should NOT be 6. Behaves the same if canvas is added as a dependency in package.json and run `npm install` [code

Error Output

Error: command failed

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
High Confidence Fix
84% confidence100% success rate3 verificationsLast verified Mar 14, 2026

Solution: npm default install command always runs if binding.gyp exists, and package install script is ignored

Low Risk

We have a very similar issue currently. Our builds started failing after this change to dd-native-metrics: https://github.com/DataDog/dd-native-metrics-js/pull/21 Here's a list of things that are the same or similar as in your case: - `node-gyp rebuild` gets run when installing this package and we don't understand why - Works with npm 6 - Does not work with npm 8 - We are using a private npm reg

84

Trust Score

3 verifications

100% success
  1. 1

    We have a very similar issue currently. Our builds started failing after this ch

    We have a very similar issue currently. Our builds started failing after this change to dd-native-metrics: https://github.com/DataDog/dd-native-metrics-js/pull/21

  2. 2

    Here's a list of things that are the same or similar as in your case:

    Here's a list of things that are the same or similar as in your case:

  3. 3

    `node-gyp rebuild` gets run when installing this package and we don't understand

    - Works with npm 6 - Does not work with npm 8 - We are using a private npm registry w/ Artifactory. The issue does _not_ occur when installing from the public npm registry.

  4. 4

    Here's a list of things that are dissimilar:

    Here's a list of things that are dissimilar:

Validation

Resolved in npm/cli GitHub issue #5234. Community reactions: 2 upvotes.

Verification Summary

Worked: 3
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

npmpackage-managernodejsrelease-8.xbugneeds-triage