Skip to content
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 install removes resolved and integrity properties from package-lock.json if installed from cache #4263

Open
2 tasks done
SymbioticKilla opened this issue Jan 19, 2022 · 20 comments
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release

Comments

@SymbioticKilla
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

If you run npm install with existing package cache inside "node_modules" it creates packages-lock.json without "resolved" and "integrity" properties.

Expected Behavior

"resolved" and "integrity" properties should stay remain after npm install using cache from "node_modules" folder

Steps To Reproduce

1.) Run npm install
2.) package-lock.json is created
3.) node modules are cached inside the project folder under "node_modules" folder
4.) delete package-lock.json and delete one package form "node_modules" folder
5.) Run npm install
6.) package-lock.json is created, but "resolved" and "integrity" properties are removed from each package descriptions inside package-lock.json

Environment

  • npm: 8.1.2
  • Node.js: 16.3.2
  • OS Name: Windows 10
  • System Model Name:
  • npm config:
; copy and paste output from `npm config ls` here
@SymbioticKilla SymbioticKilla added Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release labels Jan 19, 2022
@giovannipds
Copy link

giovannipds commented Feb 24, 2022

In my case, it removes the resolved entry for a company's remote repository, causing the CI pipeline to fail.

  • npm 8.1.3
  • node v16.3.0
  • Mac OS

@ljharb
Copy link
Contributor

ljharb commented Feb 25, 2022

@giovannipds what about with npm v8.5.2?

@giovannipds
Copy link

@ljharb thanks for interacting. In my case, the issue was in my repository config, it was misconfigured, that's why my resolveds were being removed. Probably not related to what this ticket is about. What fixed for me:

npm config set registry #YOUR_COMPANY_REGISTRY_URL

olizilla added a commit to web3-storage/web3.storage that referenced this issue Apr 19, 2022
bring back lost `resolved` and `integrity` properties

see: npm/cli#4263

License: (Apache-2.0 AND MIT)
Signed-off-by: Oli Evans <[email protected]>
@vmasek
Copy link

vmasek commented Jul 3, 2022

I managed to get proper package-lock.json (with integrity and resolve fields) after:

  • cleaning the npm cache npm cache clean -f
  • removing node_modules in project folder
  • removing the package-lock.json file
  • running npm install in now "clean" project folder

@aarowman
Copy link

Just ran into this issue on npm 8.19.2 with node v18.12.1.

Cleared the cache and re-ran npm install (slow), then it was ok

@cdpark0530
Copy link

I encountered the same issue with nodejs 16.19.1 and npm 8.19.3

@daksh-sagar
Copy link

encountered the same issue with node 14.18.0 and npm 8.19.3

@sorgloomer
Copy link

Happened on npm v9.5.0 too. vmaseks workaround worked.

@kfayelun
Copy link

kfayelun commented Jul 5, 2023

We also get this. Repeatedly. And it breaks our CI. Started after we updated to new versions of node and npm recently I think, but I see others get it on older versions as well. I'm not 100% if that is what cased it, as we have refactored a lot of stuff lately.
Current versions:
Node: 18.16.0
npm: 9.6.7
old versions:
Node: 16.5.1
npm: not sure unfortunately, but v8.x.x something

Only workaround is @vmasek workaround above. Would love to not have to delete package-lock.json the whole time, any idea whats causing this or if/when it will be fixed?

@rbell-mfj
Copy link

For those who dislike the idea of unlocking and potentially version-bumping a ton of dependencies by deleting package-lock, here's a variant of the workaround above that seems to have worked for us:

  1. Delete node_modules folder
  2. Restore package-lock.json from a recent commit prior to the undesired property removal (but keep the existing package.json version)
  3. Run npm install

This should preserve the locked versions of any packages that were already installed prior to the corruption of package-lock, while ensuring anything newer based on package.json also gets installed/updated.

@Rapol
Copy link

Rapol commented Sep 7, 2023

I had this happened to me during npm solving merge conflicts with npm-merge-driver. Similarly to @rbell-mfj, I restored package-lock.json before merge conflict resolution, applied the updates manually, integrity and resolved were kept.

@LendaVadym
Copy link

I faced the same problem with node 18.12.1 and npm 8.19.2
Had to do actions proposed by vmasek to resolve the problem.

@felschr
Copy link

felschr commented Oct 16, 2023

While this problem persists, npm-lockfile-fix provides an easy way to fix lock files without having to delete & regenerate them. It's less problematic since it doesn't cause any dependency updates.

Also it seems that these are duplicates or related issues: #4460 #6301

Desplandis added a commit to Desplandis/itowns that referenced this issue Dec 5, 2023
Caused by an issue of command npm install (see npm/cli#4263).
Introduced by commit a841343
Desplandis added a commit to iTowns/itowns that referenced this issue Dec 5, 2023
Caused by an issue of command npm install (see npm/cli#4263).
Introduced by commit a841343
eseidel added a commit to shorebirdtech/website that referenced this issue Jan 25, 2024
eseidel added a commit to shorebirdtech/website that referenced this issue Jan 25, 2024
* chore: add sitemap

Google search console suggested we do this?  No clue if it's
a good idea or worth doing.

* Include sitemap in layout.astro

* chore: run npm upgrade

Attempting to appease the npm gods.

* workaround npm/cli#4263

* Run npm format
AnthonyGlt pushed a commit to AnthonyGlt/itowns that referenced this issue Feb 22, 2024
Caused by an issue of command npm install (see npm/cli#4263).
Introduced by commit a841343
@CommanderOfCode
Copy link

CommanderOfCode commented Feb 23, 2024

I wonder if the npm team will ever pick this issue up? It's still happening.

@GMartigny
Copy link

Has this issue today, solved it with running npm cache clear --force (not sure if this was useful) and npm update.

@klausbadelt
Copy link

.. solved it with ... npm update.

npm update, or deleting package-lock.json then npm install, IMHO defeats the purpose of package-lock.json and can cause issues downstream (different dependency versions, failing tests, failing deploys, bugs...).
We have package-lock.json change 'randomly' after npm install from different developers. All on the same (at least major) version, causing CI delays (busted cache).
So, our problem is similar albeit not related to deleting package-lock.json (which we do not recommend every anyway): Subsequent npm installs on different machines change package-lock.json "resolved" and "integrity" entries. Would love to see this solved.

@sorgloomer
Copy link

.. solved it with ... npm update.

npm update, or deleting package-lock.json then npm install, IMHO defeats the purpose of package-lock.json and can cause issues downstream (different dependency versions, failing tests, failing deploys, bugs...). We have package-lock.json change 'randomly' after npm install from different developers. All on the same (at least major) version, causing CI delays (busted cache). So, our problem is similar albeit not related to deleting package-lock.json (which we do not recommend every anyway): Subsequent npm installs on different machines change package-lock.json "resolved" and "integrity" entries. Would love to see this solved.

This might be a dumb suggestion, but couldn't you just ask your developers not to change the package-lock? For example, tell them to use npm ci on their dev machines instead of npm install unless they are intentionally updating packages.

plietar added a commit to mrc-ide/packit that referenced this issue Aug 23, 2024
When building Packit with Nix (and other sandboxed build systems), these
fields are used to prefetch the dependencies. For some reason they are
missing from our file for all but one dependency. There seems to be some
npm bug that causes these fields to be removed under certain conditions
(npm/cli#4263, npm/cli#6301).

Deleting the lockfile and running `npm install` again produces a new
file that has the missing fields. However in doing so all the
dependencies are updated, which I'd rather not right now. Instead I used
the script at https://github.com/jeslie0/npm-lockfile to add the fields
without changing the version numbers.
WilliButz added a commit to nix-community/authentik-nix that referenced this issue Sep 7, 2024
Release notes: https://docs.goauthentik.io/docs/releases/2024.8

Still includes the same hacky workaround for one of the dependencies
that was introduced in the 2024.6.1 update. See components/docs.nix for
more information.

Also, as upstream package-lock.json files do not include source hashes
and urls for a lot of dependencies, building authentik from source is
only possible after they've been resolved. This makes it kind of a
gamble to try and reproduce a build with the same set of dependencies
that the devs use. This is why the two relevant lock files are vendored
here now. See upstream issues for more information:
- goauthentik/authentik#6180
- goauthentik/authentik#11169
and the npm issue for the underlying reason:
npm/cli#4263

Flake lock file updates:

• Updated input 'flake-parts':
    'github:hercules-ci/flake-parts/8471fe90ad337a8074e957b69ca4d0089218391d' (2024-08-01)
  → 'github:hercules-ci/flake-parts/567b938d64d4b4112ee253b9274472dc3a346eb6' (2024-09-01)
• Updated input 'flake-parts/nixpkgs-lib':
    'https://github.com/NixOS/nixpkgs/archive/a5d394176e64ab29c852d03346c1fc9b0b7d33eb.tar.gz?narHash=sha256-uFf2QeW7eAHlYXuDktm9c25OxOyCoUOQmh5SZ9amE5Q%3D' (2024-08-01)
  → 'https://github.com/NixOS/nixpkgs/archive/356624c12086a18f2ea2825fed34523d60ccc4e3.tar.gz?narHash=sha256-Ss8QWLXdr2JCBPcYChJhz4xJm%2Bh/xjl4G0c0XlP6a74%3D' (2024-09-01)
• Updated input 'nixpkgs':
    'github:NixOS/nixpkgs/c374d94f1536013ca8e92341b540eba4c22f9c62' (2024-08-21)
  → 'github:NixOS/nixpkgs/574d1eac1c200690e27b8eb4e24887f8df7ac27c' (2024-09-06)
• Updated input 'poetry2nix':
    'github:nix-community/poetry2nix/884b66152b0c625b8220b570a31dc7acc36749a3' (2024-08-21)
  → 'github:nix-community/poetry2nix/a313fd7169ae43ecd1a2ea2f1e4899fe3edba4d2' (2024-09-05)
@klausbadelt
Copy link

This might be a dumb suggestion, but couldn't you just ask your developers not to change the package-lock? For example, tell them to use npm ci on their dev machines instead of npm install unless they are intentionally updating packages.

npm ci amongst other things deletes all node_modules folders. This would slow us down quite a bit. I also think original intent was CI, not local dev.

yurishkuro pushed a commit to jaegertracing/jaeger-ui that referenced this issue Oct 14, 2024
## Which problem is this PR solving?
- Add missing integrity checks to package-lock.json

## Description of the changes
- I noticed some lockfile entries didn't have the `resolved` and
`integrity` field set. This PR fixed that.
- I think it's related to this npm issue:
npm/cli#4263

## How was this change tested?
- no functional change

## Checklist
- [X] I have read
https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md
- [X] I have signed all commits
- [ ] I have added unit tests for the new functionality
- [ ] I have run lint and test steps successfully
  - for `jaeger`: `make lint test`
  - for `jaeger-ui`: `yarn lint` and `yarn test`

Signed-off-by: Andreas Gerstmayr <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release
Projects
None yet
Development

No branches or pull requests