-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
[BUG] npm install
modifies yarn.lock in incorrect ways
#5126
Comments
Is this something the npm cli team would want to have fixed? I might attempt submitting a patch for it if so, but some confirmation that the team sees it as an issue (and it's not on purpose) first would be nice so I could avoid wasting time on a patch, if it has no chance of being accepted. CC @wraithgar @ljharb |
i think there's two separate issues here.
i'm curious, is this something that's surfacing now because yarn changed the format of their lock file? it's very probable that our compatibility layer there is old and out of date, but if we change it we need to make sure it plays nicely with older formats as well.
we would absolutely love to have your help getting this fixed! to give you a bit of a head start, the relevant code is found here reading the comments there, it looks like we explicitly chose to not use the canonical |
npm install
should not modify yarn.locknpm install
modifies yarn.lock in incorrect ways
notice the same issue, any update on the thread? |
cf #5317 |
Since #5317 has been combined with this ticket, please make sure that |
Is there a command line option to prevent this obnoxious behavior? |
@nlf This issue is even worse when using a yarn v2 lockfile that has a completely different format. There should be a simple option for npm to ignore yarn.lock completely. Both for restore and for writing. This issue comes up if you build a workspace with both yarn and npm managed packages. This happens if you combine multiple packages for local development in an environment where different teams use different package managers. |
Workaround for key order This way you don't completely mess up the history of your |
I mean, the workaround is just to restore the file with |
@alamothe But then you lose any legit changes made by npm, too, like npm install/update/... . If not many you can carry them over manually. @wraithgar @shalvah Thanks for taking care of this in PR#5724. |
@victorb Fixed in #5751 in v9.0.1 by @wraithgar |
According to #5659 this doesn't address all of the issues, only some. |
@cachius what is the use case for using |
One use case is installing listed peer dependencies via npm in a Yarn project with the |
Why on earth is NPM even changing the lockfile. We're using The big issue however, is that it's a Yarn 3 project, with a v6 lockfile, and then NPM overwrites it fully with a v1 lockfile which broke the rest of our pipeline. |
I find that this behavior breaks our CI pipeline, since we run |
It was incorrectly modified by npm install: npm/cli#5126
what is the use case for using npm to manage yarn.lock? Why not just use yarn? |
Is there an existing issue for this?
This issue exists in the latest npm version
Current Behavior
If you run
npm install
in a project that has ayarn.lock
file, npm changes both the syntax, data and order ofyarn.lock
file.Changes I've spotted that shouldn't happen:
is-number@^7.0.0:
becomes"is-number@^7.0.0":
,version
becomes"version"
and so on)"https://registry.yarnpkg.com/is-number/-/is-number-7.0.0.tgz#7535345b896734d5f80c4d06c50955527a14f12b"
becomes"https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz"
)yarn.lock
hasversion
,resolved
,integrity
in that order, afternpm install
, the order becomesintegrity
,resolved
,version
)Expected Behavior
No commands run with
npm
should modify filesnpm
doesn't have anything to do with, namelyyarn.lock
which is managed by a different program thannpm
.Steps To Reproduce
cd $(mktemp -d)
Create new temporary directory for a test projectnpm init --yes
Create new package.jsonnpm install --save is-number
Add a dependencyyarn install
Install dependencies via yarn, creating theyarn.lock
filecp yarn.lock yarn.lock.original
Save a copy of the originalyarn.lock
filenpm install
Run npm install again which modifies theyarn.lock
file unexpectedlydiff yarn.lock yarn.lock.original
show the difference between the npm-modified yarn.lock file with the original one that yarn itself producesEnvironment
8.13.2
v18.4.0
Arch Linux
Desktop
The text was updated successfully, but these errors were encountered: