[BUG] running `npm update` erases the `name` field from `package-lock.json`
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
running npm update erases the name field from package-lock.json for workspaces.
When the name field is missing other cli commands like npm audit get confused.
Expected Behavior
running npm update does not have unexpected side effects in projects that use workspaces
Steps To Reproduce
I've created a reproduction here: https://github.com/romainmenke/npm-update-bug-1
run npm update and then git diff on branch main to see the effects on package-lock.json
I've also create a pull request with this same diff : https://github.com/romainmenke/npm-update-bug-1/pull/1
Environment
- npm: 8.18.0
- Node.js: v18.8.0
seems related :
- https://github.com/npm/cli/issues/4608
- https://github.com/npm/cli/issues/4521
Experiencing similar problems with v9.1.1. It is not just update that has a problem. Observations in a new project:
npm inita new projectnpm init -w foo/barcreates an entry in package-lock.json with name. Specify a package name of@foo/bar.npm init -w foo/bar2creates an entry in package-lock.json without name. Specify a package name of@foo/bar2.npm init -w foo/bar3creates an entry in package-lock.json without name but adds name to the foo/bar2 entry. Specify a package name of@foo/bar3.- Running
npm lsafter creating bar2 and bar3 gets an error on foo/bar3.
Oddly, the bar2/3 entries also get devDependencies attributes.
Repair:
- Delete package-lock.json
- Run
npm install --workspaces npm lsruns successfully. The names are present in the package-lock.json file
Regression:
- Run
npm update- name is dropped from all workspace nodes in the package-lock.json file npm lsfails with an error on every workspace
Edge.js was setting outer edges invalid due to missing name. Have not tracked back to why name is not set in the first place.
Edited to indicate package names should be specified when creating the new workspaces.