[BUG] Inconsistency between `npm install` and `npm audit fix` for `name` in package-lock.json
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 10.1k
- Forks
- 4.7k
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 19
Description
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
npm install and npm audit fix make inconsistent changes to the package-lock.json, causing unnecessary differences for that file.
npm installdoes not include anamefor the""packagesentrynpm auditincludes aname
This means that running npm audit adds a name property, and a subsequent npm install run removes it again.
Expected Behavior
npm install and npm audit fix should behave consistently. Either both should create a name property, or neither of them should create it.
Steps To Reproduce
ℹ️ indicates observed behavior.
❌ indicates unexpected observed behavior.
- Create a folder
npm-audit-test - Create a
package.jsonfile with the following content:{ "private": true, "devDependencies": { "minimist": "1.2.5" } } - In that folder run
npm install - Inspect the
package-lock.jsonfile
ℹ️ It has the following content:{ "name": "npm-audit-test", "lockfileVersion": 2, "requires": true, "packages": { "": { "devDependencies": { "minimist": "1.2.5" } }, ... } - Run
npm audit fix --force - Inspect the
package-lock.jsonfile
❌ It has the following content; note the extranameproperty for the""packagesentry{ "name": "npm-audit-test", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "npm-audit-test", "devDependencies": { "minimist": "^1.2.6" } }, ... } - Run
npm installagain - Inspect the
package-lock.jsonfile
❌ Thenameproperty was removed again
Environment
- npm: 8.5.0
- Node.js: v16.14.2
- OS Name: Microsoft Windows [Version 10.0.19043.1586]
- System Model Name:
- npm config:
; "builtin" config from C:\Program Files\nodejs\node_modules\npm\npmrc
prefix = "C:\\Users\\<redacted>\\AppData\\Roaming\\npm"
; node bin location = C:\Program Files\nodejs\node.exe
; cwd = C:\Users\<redacted>\Downloads\npm-audit-test
; HOME = C:\Users\<redacted>
; Run `npm config ls -l` to show all defaults.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the difference using the issue's npm-audit-test steps, comparing package-lock.json after npm install and npm audit fix --force. Trace the package-lock.json generation paths for both commands and make their handling of the empty packages entry consistent, then repeat the listed commands to verify that the name property no longer appears inconsistently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100