You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] package.json has "lockfileVersion": 2 but is missing "hasInstallScript": true #2606
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 the postinstall scripts of all of your dependencies, resulting in broken packages. This appears to be because of a missing "hasInstallScript": true in my package-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 a package-lock.json file with "lockfileVersion": 1 with npm v7. This upgrades the package-lock.json file to "lockfileVersion": 2 but doesn't add "hasInstallScript": true where it would usually be added. That then causes npm 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 a package-lock.json file that has been upgraded from "lockfileVersion": 1 to "lockfileVersion": 2 to behave the same as npm ci on a package-lock.json file that was always "lockfileVersion": 2.
Steps To Reproduce:
Steps to demonstrate the current unexpected behavior:
$ npm i -g [email protected]
$ echo'{}'> package.json
$ npm i [email protected]
$ cat package-lock.json | grep -E 'lockfileVersion|hasInstallScript'"lockfileVersion": 1,
$ npm i -g [email protected]
$ npm i [email protected]
$ cat package-lock.json | grep -E 'lockfileVersion|hasInstallScript'"lockfileVersion": 2,
$ npm ci
$ ./node_modules/.bin/esbuild --version
Error: esbuild: Failed to install correctly
I'm getting the same thing with [email protected]. I installed it like normal, used it, commited package.json and package-lock.json, and then when I clone the repo at a different place and try to run it, it doesn't work.
Then 🎉
npm i electron@10 installs [email protected], and updates package.json to say so
I revert the change in package.json, changing version back to 11.2.3
@evanw
Verified that this issue is replicable even on the latest version of npm.
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 async [_complete]. we should be seeing a log that let's the user know that the existing package-lock.json file was created with an older version of npm so a one-time touch up is occuring but it never reaches that line of code due to the flag.
Side note, I do believe this issue can be resolved by also removing both node_modules and package-lock.json once you've updated to npm@7 and running npm install since those deps no longer exist. Me and @isaacs tested a scenario like this during our pairing.
Here's a PR with a potential fix for us to discuss.
Re-run npm install to regenerate the package-lock.json
Verify that "node_modules/esbuild".hasInstallScript is true in the newly generated package-lock.json
But [email protected] still complaining its postinstall script was not run.
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` error
npm 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 yorkie and npm install (no ci or existed package lock).
The rather useful fix-has-install-script package can be used to fix a corrupt lock file.
npx fix-has-install-script
This bug does appear to have an additional, knock-on effect due to the fallback behaviour of the run-script package.
In the perceived absence of an install script, run-script will always try node-gyp rebuild when binding.gyp is found - see npm/run-script#5
To ensure installation is as human-friendly as possible, sharp provides a guard in its install script to prevent node-gyp from running when we know up-front that it will fail. This bug causes the double whammy of preventing the installation of prebuilt binaries and removing the guard, so anyone it affects gets the full node-gyp error treatment.
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.
We can reproduce this bug with:
node 16.17.1 npm 8.15.0
node 16.17.1 npm 9.2.0
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
create a .npmrc file and add a private registry like this:
registry=https://...your registry url...
delete the package-lock.json
npm install
result:
in the package-lock.json for node_modules/electron the HasInstallScript is missing. Because of that the postinstall script of electron does not execute and thus the node_modules/electron/dist folder is missing.
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.
Activity
darcyclarke commentedon Feb 12, 2021
@evanw thanks for filing. We're going to investigate further.
bl-ue commentedon Feb 17, 2021
I'm getting the same thing with
[email protected]. I installed it like normal, used it, commitedpackage.jsonandpackage-lock.json, and then when I clone the repo at a different place and try to run it, it doesn't work.Then 🎉
npm i electron@10installs[email protected], and updatespackage.jsonto say sopackage.json, changing version back to11.2.3npm i[email protected]is backgit statusshows one modified file:package-lock.jsongit diff:P.S. as did @evanw I initially installed the packages with npm 6 then I upgraded to npm 7.
17 remaining items
Magador commentedon Jun 3, 2021
We have this problem also.
A workaround that we did without changing the dependencies versions is :
7.15.0package-lock.jsonhaving"lockfileVersion": 1but missing"hasInstallScript": truenode_modulesfolderpackage-lock.jsonnode_modules/.package-lock.jsonnpm installto re-generate a newpackage-lock.jsonwith same versions and"hasInstallScript": truenpm cito reinstall dependencies and execute install scriptsIf you have any peerDependencies conflicts you may need to :
--legacy-peer-deps--forcegijun19 commentedon Jun 4, 2021
@evanw
Verified that this issue is replicable even on the latest version of npm.
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
async [_complete]. we should be seeing a log that let's the user know that the existing package-lock.json file was created with an older version of npm so a one-time touch up is occuring but it never reaches that line of code due to the flag.Side note, I do believe this issue can be resolved by also removing both
node_modulesandpackage-lock.jsononce you've updated tonpm@7and runningnpm installsince those deps no longer exist. Me and @isaacs tested a scenario like this during our pairing.Here's a PR with a potential fix for us to discuss.
npm/arborist#287
CC: @darcyclarke
compulim commentedon Jul 15, 2021
With
[email protected], still no luck after nukingnode_modulesandpackage-lock.json. My steps:[email protected]and[email protected]node_modulesandpackage-lock.jsonnpm config get ignore-scriptsisfalsenpm installto regenerate thepackage-lock.json"node_modules/esbuild".hasInstallScriptistruein the newly generatedpackage-lock.jsonBut
[email protected]still complaining itspostinstallscript was not run.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` error
Artoria9 commentedon Aug 10, 2021
FYI, install/uninstall script in deps is still bugged at v7.20.3 with node 16. Tested with an fresh project with
yorkieand npm install (no ci or existed package lock).lovell commentedon Sep 21, 2021
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
run-scriptpackage.In the perceived absence of an
installscript,run-scriptwill always trynode-gyp rebuildwhenbinding.gypis found - see npm/run-script#5To ensure installation is as human-friendly as possible, sharp provides a guard in its
installscript to preventnode-gypfrom running when we know up-front that it will fail. This bug causes the double whammy of preventing the installation of prebuilt binaries and removing the guard, so anyone it affects gets the fullnode-gyperror treatment.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.
manid commentedon Dec 7, 2021
npm i --package-lock-only$ npm --version
8.1.0
$ node --version
v17.0.1
krazyjakee commentedon Jan 3, 2022
Can confirm the issue is still present in npm 8.3.0
BoBoooooo commentedon Jan 20, 2022
still have this issue
JasonFoglia commentedon Jul 14, 2022
Is there an update to this issue? Running in pipelines and cannot build the project.
vchuchkalov commentedon Aug 17, 2022
It is still being reproduced
grafanauser commentedon Jan 18, 2023
We can reproduce this bug with:
node 16.17.1 npm 8.15.0
node 16.17.1 npm 9.2.0
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:
registry=https://...your registry url...
result:
in the package-lock.json for node_modules/electron the HasInstallScript is missing. Because of that the postinstall script of electron does not execute and thus the node_modules/electron/dist folder is missing.
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.