-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
[BUG] package.json has "lockfileVersion": 2 but is missing "hasInstallScript": true #2606
Comments
@evanw thanks for filing. We're going to investigate further. |
I'm getting the same thing with Then 🎉
diff --git a/package-lock.json b/package-lock.json
index 0a2c93a..bb080c7 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -211,6 +211,7 @@
"version": "11.2.3",
"resolved": "https://registry.npmjs.org/electron/-/electron-11.2.3.tgz",
"integrity": "sha512-6yxOc42nDAptHKNlUG/vcOh2GI9x2fqp2nQbZO0/3sz2CrwsJkwR3i3oMN9XhVJaqI7GK1vSCJz0verOkWlXcQ==",
+ "hasInstallScript": true,
"dependencies": {
"@electron/get": "^1.0.1",
"@types/node": "^12.0.12", P.S. as did @evanw I initially installed the packages with npm 6 then I upgraded to npm 7. |
I tried to fix the |
Same problem here when preparing the update from npmv6 to npmv7. As a workaround I manually edited the package-lock.json and added IMO this is a critical bug and should be fixed in npm soon, especially when more and more people are updating. |
To add 2p., the issue of |
@bl-ue Saw the same issue when upgrading to 7.x |
@evanw can you try updating to the latest version of npm? (ie. Here's a quick screen from my test just now to try & replicate (and can't): |
This problem is most definitely not fixed. Here's the same demonstration of the broken behavior from the original post with all versions updated to the latest versions. This demonstrates that the same bug is still happening: $ npm i -g npm@6.14.13
$ echo '{}' > package.json
$ npm i esbuild@0.11.10
$ cat package-lock.json | grep -E 'lockfileVersion|hasInstallScript'
"lockfileVersion": 1,
$ npm i -g npm@7.9.0
$ npm i esbuild@0.11.10
$ cat package-lock.json | grep -E 'lockfileVersion|hasInstallScript'
"lockfileVersion": 2,
$ npm ci
$ ./node_modules/.bin/esbuild --version
Error: esbuild: Failed to install correctly
Make sure you don't have "ignore-scripts" set to true. You can check this with
"npm config get ignore-scripts". If that returns true you can reset it back to
false using "npm config set ignore-scripts false" and then reinstall esbuild.
If you're using npm v7, make sure your package-lock.json file contains either
"lockfileVersion": 1 or the code "hasInstallScript": true. If it doesn't have
either of those, then it is likely the case that a known bug in npm v7 has
corrupted your package-lock.json file. Regenerating your package-lock.json file
should fix this issue. Each step explainedHere is the demonstration of the bug broken down in detail:
I've tried to explain everything but please let me know if any part of this is still confusing, or if you're not able to reproduce the issue by following the steps in this comment. Potential solutionsI would really like to get this fixed. Trying to direct users to try to fix corrupted
I don't have an opinion on which approach npm takes; I'd just like to see the bug fixed. There may potentially be other ways of solving this as well. |
The problem is not fixed, I can also reproduce it with npm 7.11.0, please see below. @darcyclarke Could you please reopen it?
|
We have this problem also. A workaround that we did without changing the dependencies versions is :
If you have any peerDependencies conflicts you may need to :
|
@evanw The issue is stemming from when we build ideal trees and whether or not we use reify or open up a tarball and look inside for the relevant metadata via Side note, I do believe this issue can be resolved by also removing both Here's a PR with a potential fix for us to discuss. CC: @darcyclarke |
With
But Strangely it only repro on GitHub Actions (Ubuntu 20.04.2 LTS). I can never repro it on my local Ubuntu. Expand to see `esbuild` errornpm ERR! throw new Error(`esbuild: Failed to install correctly npm ERR! ^ npm ERR! npm ERR! Error: esbuild: Failed to install correctly npm ERR! npm ERR! Make sure you don't have "ignore-scripts" set to true. You can check this with npm ERR! "npm config get ignore-scripts". If that returns true you can reset it back to npm ERR! false using "npm config set ignore-scripts false" and then reinstall esbuild. npm ERR! npm ERR! If you're using npm v7, make sure your package-lock.json file contains either npm ERR! "lockfileVersion": 1 or the code "hasInstallScript": true. If it doesn't have npm ERR! either of those, then it is likely the case that a known bug in npm v7 has npm ERR! corrupted your package-lock.json file. Regenerating your package-lock.json file npm ERR! should fix this issue. |
FYI, install/uninstall script in deps is still bugged at v7.20.3 with node 16. Tested with an fresh project with |
The rather useful fix-has-install-script package can be used to fix a corrupt lock file.
This bug does appear to have an additional, knock-on effect due to the fallback behaviour of the In the perceived absence of an To ensure installation is as human-friendly as possible, sharp provides a guard in its I've had recent reports about this from people who are using the latest npm v7.24.0 so it's unclear if npm/arborist#287 has fixed this. |
$ npm --version
|
Can confirm the issue is still present in npm 8.3.0 |
still have this issue |
Is there an update to this issue? Running in pipelines and cannot build the project. |
It is still being reproduced |
We can reproduce this bug with: and the official electron quick start repo and using a private repository, without updating an npm version or whatever, just by creating a fresh package-lock.json steps to reproduce:
result: the workaround described by @Magador works for us in most cases, not all. We did not use npm ci, but deleted node_modules/electron before npm install though. |
My apologies if this is a duplicate. The closest I could find is #1905, but the fix didn't solve the problem in this issue.
Current Behavior:
The user-facing issue is that you can get into a state where
npm ci
fails to run thepostinstall
scripts of all of your dependencies, resulting in broken packages. This appears to be because of a missing"hasInstallScript": true
in mypackage-lock.json
file.I'm not familiar with npm's internals but I did some debugging and I believe one way to get into this state is by running
npm install
on apackage-lock.json
file with"lockfileVersion": 1
with npm v7. This upgrades thepackage-lock.json
file to"lockfileVersion": 2
but doesn't add"hasInstallScript": true
where it would usually be added. That then causesnpm ci
to fail to reinstall the package correctly. There may also be other ways of getting into this state.Expected Behavior:
I expect running
npm ci
on apackage-lock.json
file that has been upgraded from"lockfileVersion": 1
to"lockfileVersion": 2
to behave the same asnpm ci
on apackage-lock.json
file that was always"lockfileVersion": 2
.Steps To Reproduce:
Steps to demonstrate the current unexpected behavior:
Steps to demonstrate the desired behavior:
Environment:
The text was updated successfully, but these errors were encountered: