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
[BUG] npm always writes a repository name into the package-lock.json file when not specified in package.json (lock file changes depending on local repository name)
#8008
Open
2 tasks done
Standard8 opened this issue
Jan 2, 2025
· 0 comments
When I create a package.json that does not have a name value, then npm automatically adds a name field depending on the local repository directory name.
This causes additional, unexpected changes, when different developers update the installed packages. It also may cause confusion that the package.json does not specify a name, but the lock file does.
#2264 was the original version of this, but has been closed, and unfortunately the issue does not appear to be fully resolved
Expected Behavior
Since the name property is optiona, there should be no top-level name property in the package-lock.json file if one is not specified in the package.json file.
Steps To Reproduce
Run $ mkdir npmtest && cd npmtest
Create a package.json file with the content:
{}
Run $ npm install
Examine the created package-lock.json file.
=> The package-lock.json file contains a "name": "npmtest", line at the top-level.
Rename the directory ($ cd .. && mv npmtest npmtest1)
Run $npm install again
=> The package-lock.json file now contains "name": "npmtest1", at the top-level.
Environment
npm: 11.0.0
Node.js: 23.5.0
OS Name: macOS
System Model Name:
npm config:
; "user" config from /Users/mark/.npmrc; node bin location = /opt/homebrew/Cellar/node/23.5.0/bin/node; node version = v23.5.0; npm local prefix = /Users/mark/dev/npmtest; npm version = 11.0.0; cwd = /Users/mark/dev/npmtest1; HOME = /Users/mark
The text was updated successfully, but these errors were encountered:
Is there an existing issue for this?
This issue exists in the latest npm version
Current Behavior
When I create a
package.json
that does not have aname
value, then npm automatically adds a name field depending on the local repository directory name.This causes additional, unexpected changes, when different developers update the installed packages. It also may cause confusion that the
package.json
does not specify a name, but the lock file does.#2264 was the original version of this, but has been closed, and unfortunately the issue does not appear to be fully resolved
Expected Behavior
Since the
name
property is optiona, there should be no top-levelname
property in thepackage-lock.json
file if one is not specified in thepackage.json
file.Steps To Reproduce
$ mkdir npmtest && cd npmtest
package.json
file with the content:$ npm install
package-lock.json
file.=> The
package-lock.json
file contains a"name": "npmtest",
line at the top-level.$ cd .. && mv npmtest npmtest1
)$npm install
again=> The
package-lock.json
file now contains"name": "npmtest1",
at the top-level.Environment
The text was updated successfully, but these errors were encountered: