-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Self-service
- I'd be willing to implement a fix
Describe the bug
This is basically a repeat of my request that yarn install --frozen-lockfile should be the default, now though with the --immutable flag instead.
Use case:
yarn init
yarn add moment
npm install --save lodash
yarn install
Now, running yarn install would mutate the lock as the package.json and yarn.lock and are out of sync.
yarn install --immutable would provide an error.
(The usage of npm is a mistake in this workflow. Yet yarn should not resolve the package.json and mutate the lockfile by itself. yarn should error on the side of caution in order to ensure its claim to offer:
Safe, stable, reproducible projects
I still think that mutating the lockfile is something that yarn should almost never do, unless it is about adding or removing a dependency.
Though I also want to point out that berry does a lot of things better than the old yarn.
1.) CI env variable allows immutable implicitly. That is great!
I figured I could get my wanted behavior via:
CI=true yarn install
to force a default of --immutable without setting it.
2.) immutable can be set in yarn.rc AND overwritten on the fly in order to sync the package
I added:
enableImmutableInstalls: truethis makes all installs use immutable. If I want to sync the packages, I can use:
yarn install --no-immutable
to force the sync.
This means that having this setting in the each repo's .yarnrc.yml
(This means that yarnpkg/yarn#4570 was solved for berry.)
Though I was a bit surprised that I could use --no-immutable, as this is not part of the help, yet one can find it e.g. referenced here.
(I created a follow up to improve the docs / man pages: #7023 )
yarn install -h | grep no-
so having a more clear documentation for the --no- prefix would be awesome.
To reproduce
yarn init
yarn add moment
npm install --save lodash
yarn install
yarn install should fail but succeeds:
yarn install
➤ YN0087: Migrated your project to the latest Yarn version 🚀
➤ YN0000: · Yarn 4.12.0
➤ YN0000: ┌ Resolution step
➤ YN0085: │ + lodash@npm:4.17.21, moment@npm:2.30.1
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: └ Completed
➤ YN0000: · Done in 0s 63ms
The behavior of yarn install --immutable is the expected and desired one as a default:
~ yarn install --immutable
➤ YN0000: · Yarn 4.12.0
➤ YN0000: ┌ Resolution step
➤ YN0085: │ + lodash@npm:4.17.21, moment@npm:2.30.1
➤ YN0000: └ Completed
➤ YN0000: ┌ Post-resolution validation
➤ YN0000: │ @@ -1,13 +1,27 @@
➤ YN0028: │ -# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
➤ YN0028: │ -# yarn lockfile v1
➤ YN0028: │ +# This file is generated by running "yarn install" inside your project.
➤ YN0028: │ +# Manual changes might be lost - proceed with caution!
➤ YN0000: │
➤ YN0028: │ +__metadata:
➤ YN0028: │ + version: 8
➤ YN0028: │ + cacheKey: 10c0
➤ YN0000: │
➤ YN0028: │ -lodash@^4.17.21:
➤ YN0028: │ - version "4.17.21"
➤ YN0028: │ - resolved "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz"
➤ YN0028: │ - integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
➤ YN0028: │ +"lodash@npm:^4.17.21":
➤ YN0028: │ + version: 4.17.21
➤ YN0028: │ + resolution: "lodash@npm:4.17.21"
➤ YN0028: │ + languageName: node
➤ YN0028: │ + linkType: hard
➤ YN0000: │
➤ YN0028: │ -moment@^2.30.1:
➤ YN0028: │ - version "2.30.1"
➤ YN0028: │ - resolved "https://registry.npmjs.org/moment/-/moment-2.30.1.tgz"
➤ YN0028: │ - integrity sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==
➤ YN0028: │ +"moment@npm:^2.30.1":
➤ YN0028: │ + version: 2.30.1
➤ YN0028: │ + resolution: "moment@npm:2.30.1"
➤ YN0028: │ + languageName: node
➤ YN0028: │ + linkType: hard
➤ YN0028: │ +
➤ YN0028: │ +"new_yarn@workspace:.":
➤ YN0028: │ + version: 0.0.0-use.local
➤ YN0028: │ + resolution: "new_yarn@workspace:."
➤ YN0028: │ + dependencies:
➤ YN0028: │ + lodash: "npm:^4.17.21"
➤ YN0028: │ + moment: "npm:^2.30.1"
➤ YN0028: │ + languageName: unknown
➤ YN0028: │ + linkType: soft
➤ YN0000: │
➤ YN0028: │ The lockfile would have been modified by this install, which is explicitly forbidden.
➤ YN0000: └ Completed
➤ YN0000: · Failed with errors in 0s 32msEnvironment
yarn dlx -q envinfo --preset jest
System:
OS: Linux 5.15 Ubuntu 25.04 25.04 (Plucky Puffin)
CPU: (32) x64 AMD Ryzen 9 5950X 16-Core Processor
Binaries:
Node: 24.12.0 - /tmp/xfs-cf945491/node
Yarn: 4.12.0 - /tmp/xfs-cf945491/yarn
npm: 11.6.2 - /home/philipp/.nvm/versions/node/v24.12.0/bin/npmAdditional context
No response