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

package-lock file changing based on local repository name #2264

Closed
NickAJScott opened this issue Nov 30, 2020 · 27 comments · Fixed by nodeshift/npcheck#79 · 4 remaining pull requests
Closed

package-lock file changing based on local repository name #2264

NickAJScott opened this issue Nov 30, 2020 · 27 comments · Fixed by nodeshift/npcheck#79 · 4 remaining pull requests
Assignees
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 7.x work is associated with a specific npm 7 release

Comments

@NickAJScott
Copy link

Current Behavior:

package-lock.json changes depending on name of local copy of git repo, e.g. if i have two copies of the same repo locally one which matches the name in package.json and one which doesn't i get two different package-lock files, one specifies the name of the package in the inner packages list and one doesn't.

Expected Behavior:

package-lock.json should be independent of top level directory name, when working in a team there shouldn't be unnecessary changes to package-lock file due to a team member having a different local name of their git repository.

Steps To Reproduce:

  1. clone a repository twice one in the default named directory and one into a name that differs from the repo name.
  2. run npm install
  3. two different package-lock files will be generated.

Environment:

  • OS: Ubuntu 20.04
  • Node: 15.3.0
  • npm: 7.0.14
@NickAJScott NickAJScott added Bug thing that needs fixing Needs Triage needs review for next steps Release 7.x work is associated with a specific npm 7 release labels Nov 30, 2020
@NickAJScott NickAJScott changed the title [BUG] <title> package-lock file changing based on local repository name Nov 30, 2020
@NickAJScott
Copy link
Author

I think this is in some ways similar to this issue here: #1767 The difference is the package.json does contain a name field, and when the repo name matches that name field the field is not being generated inside the package-lock.json. This means if you change the directory name the field will get generated, it seems it should be generated at all times.

@nlf
Copy link
Contributor

nlf commented Dec 4, 2020

i'm not able to reproduce this. do you have an example repo where you see this behavior? i tried cloning the same repo twice, removing the package-lock.json from both, and running npm i in both and the generated package-lock.json files match.

@NickAJScott
Copy link
Author

Hi thanks for looking into this, ill try and create a dummy repo to reproduce it.

@NickAJScott
Copy link
Author

NickAJScott commented Dec 4, 2020

@nlf Here is a repo to reproduce it: https://github.com/NickScottKortical/testpackagelock

commands i ran to see the issue were:

git clone [email protected]:NickScottKortical/testpackagelock.git
cd testpackagelock
npm install
git clone [email protected]:NickScottKortical/testpackagelock.git testpackagelock2
cd testpackagelock2
npm install

https://github.com/NickScottKortical/testpackagelock/compare/package_lock_changed

Shows the change that happens if the directory name doesn't match the name of the package, when the directory does match that name key isn't added at all and is what you see in the main branch.

@nlf nlf removed the Needs Triage needs review for next steps label Dec 4, 2020
@nlf
Copy link
Contributor

nlf commented Dec 4, 2020

confirmed! that reproduced it for me, thank you for taking the time!

@NickAJScott
Copy link
Author

No problem, glad i could help :)

@apostolos
Copy link

Can reproduce, name is added on the CI, does not happen locally (folder is named "lwjgl.org" on local filesystem):

image

@zen0wu
Copy link

zen0wu commented Jun 25, 2021

This is still reproducible and super annoying. I don't really think I understand the full picture of doing this since it seems ok to just always set ["name"] to be the one in package.json and call it a day?

@jkxyz
Copy link

jkxyz commented Jul 13, 2021

I've also run into this issue. I renamed the project directory to save myself two keystrokes: cd g<TAB> instead of cd n<TAB>g<TAB>. After noticing that my colleagues and I were committing different versions of package-lock.json in our PRs I first got us all to align on using the latest npm version thinking that was the cause of the problem. It was unexpected behavior to me that the CLI would care about the name of the package directory when generating what should be a reproducible lock file based on the project dependencies.

@ljharb ljharb added the Needs Triage needs review for next steps label Jul 13, 2021
@jonkoops
Copy link

jonkoops commented Aug 4, 2021

I can confirm this issue on NPM version 7.19.1. When the directory name the of the package is not the same as the name of the package the package lock will be modified to add the name of the package, otherwise the line is removed.

This is highly annoying as team members keep committing the package lock, even though nothing really changed.

@jonkoops
Copy link

jonkoops commented Aug 12, 2021

@nlf Any chance this could be fixed anytime soon? This is the number 1 issue that my team members are running into because some have a directory that is named the same as the package and some do not. This results in constant changes on the lockfile when committing.

@nlf
Copy link
Contributor

nlf commented Aug 12, 2021

it will be fixed in the next release, which should be getting published later today

@jonkoops
Copy link

@nlf That is great, thanks a bunch!

@StefanosGiannakis
Copy link

@jonkoops any updates? thx

@jonkoops
Copy link

@StefanosGiannakis this has been fixed and released as mentioned before in this thread.

@shreevatsa
Copy link

I still see this with npm 8.5.0 which was released in Feb 2022 (the same repro from #2264 (comment) of Dec 4 2020 above still reproduces it) — is the version with a fix newer than that?

@chrisdicarlo
Copy link

Same here with 8.18.0

@ppshobi
Copy link

ppshobi commented Sep 12, 2022

same here

@mervayar07
Copy link

  • 2264

@fm-swe
Copy link

fm-swe commented Nov 30, 2022

this is still a problem

@alxlion
Copy link

alxlion commented Dec 20, 2022

8.19.2 and issue still here. Is it possible to reopen it ?
Thanks

@fm-swe
Copy link

fm-swe commented Dec 20, 2022

maybe a solution for others running into this, I changed my script from

npm install --include=dev && npm run dev

to

npm ci --include=dev && npm run dev

to avoid this behavior.

@ashermiddleton
Copy link

I'm running into this issue in a docker environment via ddev. package-lock.json keeps updating to the top-level folder name in the docker environment "html" instead of the actual package's name and top-level folder "project".

  • Node 18.15.0
  • npm 9.5.0

@sgrossberndt
Copy link

As proposed before: Add a name-property to package.json, this will be used in package-lock.json instead of the directory name.

@sc0ttj
Copy link

sc0ttj commented Jul 3, 2023

Can this be re-opened and fixed please?

  • don't allow empty name properties:
    • take the value from the name property in package.json
    • or use the root directory name, where package.json resides
  • make npm install and npm ci consistent in this regard

samuelstroschein added a commit to opral/monorepo that referenced this issue Sep 10, 2023
Prevents package lock to use directory name. See npm/cli#2264
samuelstroschein added a commit to opral/monorepo that referenced this issue Sep 10, 2023
Prevents package lock to use directory name. See npm/cli#2264
samuelstroschein added a commit to opral/monorepo that referenced this issue Sep 11, 2023
Prevents package lock to use directory name. See npm/cli#2264
@ethankore
Copy link

Still happening.

@silverwind
Copy link

silverwind commented Apr 2, 2024

I suggest npm do the following:

  • If package.json has name, copy it into package-lock.json
  • If package.json has no name, do not write any name in package-lock.json

This will ensure matching lockfiles, regardless of the name of the parent directory.

tobni pushed a commit to pantsbuild/pants that referenced this issue Jul 11, 2024
…missing (#21159)

Closes #20859.

While this is a simple fix and addresses the linked issue, there is an
interesting edge case to discuss:

Internal packages do not necessarily have a name field in `package.json`
(see wireapp/wire-desktop#1692,
facebook/react#13107 for examples). The
JavaScript backend in Pants does require that each package.json define a
name, but I'm not so sure that's necessarily the right behavior.

It's worth considering whether we should make names optional in Pants,
given that larger JavaScript monorepos may have internal packages that
are not meant to be published. Furthermore, different JS package
managers handle this situation differently -

* [Bun doesn't handle package.json files without a
name](oven-sh/bun#6317)
* [npm assigns the parent directory name as the
name](npm/cli#2264)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment