-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
npm default install command always runs if binding.gyp exists, and package install script is ignored #5234
Comments
We have a very similar issue currently. Our builds started failing after this change to dd-native-metrics: DataDog/dd-native-metrics-js#21 Here's a list of things that are the same or similar as in your case:
Here's a list of things that are dissimilar:
|
We're getting a lot of reports of this since removing the DataDog/dd-trace-js#2239 The file doesn't exist anymore, so it's unclear why |
Seems that all of these reports share at least one thing in common: a private registry. |
This was also my assumption at first, but according to DataDog/dd-native-metrics-js#27 (comment) it seems to be isolated to newer versions of |
Oh yeah, true, it's definitely also newer versions of npm. |
I was able to reproduce with the following steps: nvm install 18.7.0
docker run -d -p 127.0.0.1:4873:4873/tcp verdaccio/verdaccio
export NPM_CONFIG_REGISTRY=http://localhost:4873
npm init -y
npm install --save @datadog/native-metrics@1.4.0
npm install --save @datadog/native-metrics@1.4.1 It looks like updating a package from a version that had a |
The issue occurs with |
Using |
@rochdev If you were to publish a new major version of |
@mkaufmaner I don't think so because in my local tests, once the issue started happening, I was unable to install any version of dd-trace anymore, even older versions that do have the |
Thank you, just thinking out loud here.
The problem is I can't implement this workaround for the thousands of CICD pipelines we have. It is simply impractical.
Well, I don't think this is a local cache problem because even when I run |
@mkaufmaner How do you generally handle updates in these pipelines? Wouldn't the same approach work in this case?
I thought the same thing, but after removing the Verdaccio container completely and running a new one I was getting the same issue. I think it's possible that |
@mkaufmaner I tried to switch version of Node with nvm to test your theory since that uses a different npm instance with its own installation folder including its cache. Even with this change I am still getting the same issue, so I'm not sure what's going on. I basically changed the instance of npm completely, and recreated the container entirely with a fresh proxy with no cached dependencies, and the issue is still there. Re-using the above workaround clears the issue again for all versions, but if I uninstall dd-trace and start over I get the issue again. I wonder if npm caches anything outside of its own folder. |
You have to pass the --force flag for the cache clean to actually work.
Without divulging too much information, I can say that updating CICD pipelines ares not assisted with automation. Thus, not a feasible solution.
I tried similar strategies with the same results. We have also opened up tickets with jFrog support to see if they have anything to add. Regardless, we can't deploy our applications and libraries that consume the |
@mkaufmaner Would environment variables work for your use case instead? The same workaround can be applied with |
Setting |
@mkaufmaner It looks like adding an empty |
Thank you, I hope this fixes the problem. |
I am seeing this issue, too, using a private registry and trying to install the |
I'm a little confused by the original issue here. This very well may be a documentation issue. Some of the additional comments don't appear to be the same as what was originally posted either. I would ask that if you have an issue that isn't the one in the main issue body to open a separate issue, it makes things very confusing very fast if folks try to glob "similar" issues into one. They may seem similar at a glance but it's likely not, under the hood. To address the "how it works/how it should work" section of this issue, this is how npm works: During install (and rebuild), npm will run any When the script running code is asked to run If I run ~/D/n/s/node-gyp $ npm view canvas scripts.install
node-pre-gyp install --fallback-to-build --update-binary
$ npm i canvas@latest --loglevel verbose --foreground-scripts
[...]
npm info run canvas@2.10.1 install node_modules/canvas node-pre-gyp install --fallback-to-build --update-binary So as far as I can tell things are working as expected. ETA: The presence of a |
Apologies if this issue is not actually the same as mine. This message made me think that this bug specifically pertains to install behavior being different when using a custom registry: |
npm does not do anything differently with scripts when using a custom registry |
All I know is that when I use my custom registry, the bug is seen, and when I use https://registry.npmjs.org the bug is not seen, and others have reported the same thing. Edit: Others in this thread have mentioned that they are using Artifactory, not Verdaccio, so if the bug were not in npm it would have to be the same bug in 2 different projects. |
The bug also appeared only in more recent versions of |
@wraithgar Here's a version: "2"
services:
node:
image: node:18.7.0
depends_on:
- registry
working_dir: /app
environment:
- NPM_CONFIG_REGISTRY=http://registry:4873
command:
- /bin/sh
- -c
- |
npm init -y
npm install --save @datadog/native-metrics@1.4.0
npm install --save @datadog/native-metrics@1.4.1
registry:
image: verdaccio/verdaccio:5.14.0 The problem exists with both Verdaccio and Artifactory, and didn't exist with npm <7. |
@rochdev what is "the problem"? |
If you run that docker-compose.yml file ( |
It actually fails to install the exact same package but with a new version that has the |
I don't know about you, but when I remove the line that installs 1.4.0 and just directly install 1.4.1, it still fails. However, your reproduction doesn't have any trouble installing the sqlite3 package, which I'm having trouble with. So maybe my issue must be a little bit different. |
Mystery solved. This is a bug in the published package
Everything seems ok. But if you actually download the package itself you find this ~/D/n/s/n/package $ curl (npm view @datadog/native-metrics@1.4.1 dist.tarball) -sO
~/D/n/s/n/package $ tar zxvf native-metrics-1.4.1.tgz package/package.json
x package/package.json
~/D/n/s/n/package $ cat package/package.json|json scripts
{
"rebuild": "node-gyp rebuild",
"lint": "node scripts/check_licenses.js && eslint .",
"test": "mocha 'test/**/*.spec.js'"
} The place npm ends up looking for scripts doesn't have an |
~/D/n/s/node-gyp $ curl (npm view @datadog/native-metrics@1.4.0 dist.tarball) -sO
~/D/n/s/node-gyp $ tar zxvf native-metrics-1.4.0.tgz package/package.json
x package/package.json
~/D/n/s/node-gyp $ cat package/package.json|json scripts
{
"install": "(node scripts/should_rebuild && node-gyp-build) || exit 0",
"rebuild": "node-gyp rebuild",
"lint": "node scripts/check_licenses.js && eslint .",
"test": "mocha 'test/**/*.spec.js'"
} |
npm only looks inside the packument for |
Closing this issue as it looks like the original issue was a misunderstanding of the docs. and the "I also have this issue" issue appears to be a bug w/ the published package and not npm. If folks have other issues I'd humbly ask that you make new issues for them so that they can be properly described in our issue template, and triaged without trying to look at multiple issues at once. |
@wraithgar We removed the |
We were forced to add back an empty |
@rochdev Let's start a new issue for this. Please include the actual error that you get when installing, and the log files if possible. |
@rochdev actually no you don't need to open a new issue. The inverse of my statement is still true. ~/D/n/s/node-gyp $ npm view @datadog/native-metrics@1.4.1 scripts
{
rebuild: 'node-gyp rebuild',
lint: 'node scripts/check_licenses.js && eslint .',
test: "mocha 'test/**/*.spec.js'",
install: 'node-gyp rebuild'
} The published version of 1.4.1 somehow had an install script still in the packument, but not in the one in the tarball. I don't think this is a registry bug, we have recently removed scripts from npm itself and the registry didn't "keep" them. Also the script isn't identical to the last version. This is either a verdaccio bug (where it merged objects before uploading? I don't know verdaccio just guessing assuming you published through verdaccio too) or some weird state w/ the package locally where that script was in the package.json before npm pack but not during. Try publishing a new version to the |
The error as-is is not an npm bug, it's doing exactly what was asked. How you published that package w/ the disconnect between the package.json in the tarball and the manifest itself is another mystery. If you can reproduce that behavior you have yourself a new bug. |
The reason this is happening in verdaccio and not against the npm registry appears to be because verdaccio does not support what we call "corgi" docs, which are streamlined packuments with some fields removed. I am debugging this right now to see if this is a problem w/ npm and how it finds package scripts. |
The reason there is an There was a |
@wraithgar So should we just make sure to remove the |
@rochdev yes that would prevent npm from auto-adding that install script during publish. You could then safely remove the |
From my perspective, this is a security issue. Spurred by Darcy's recent research on the matter, Socket Security has published a detection for this issue to help developers protect their repos from any malicious use of this potential attack vector. |
I've written a script to test for mismatches between the manifests: |
Is there a way to solve the current issue by building a proxy? |
Is there an existing issue for this?
This issue exists in the latest npm version
Current Behavior
node-gyp rebuild
running instead of the install script in package.jsonIt works correctly with npm 6.
Expected Behavior
Expect it to behave as documented:
I assume this means:
Steps To Reproduce
npm info run canvas@2.9.3 install node_modules/canvas node-gyp rebuild
is run but should NOT benpm install
It seems the problem is identified here #3341. arborist is making the decision of what install to run when it only has the manifest of the package which does not include scripts.
This error prevents the install from being successful because all the binary dependencies needed to build canvas locally are not installed. Installing the dependencies every place the install is run is not feasible for us.
The work around mentioned in #3341 of adding
"hasInstallScript": true
to package-lock.json is not feasible for us.Environment
The text was updated successfully, but these errors were encountered: