-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[Feature] Add a warning or error in Yarn Classic if package.json
's packageManager
key is set, but corepack
is not enabled
#5912
Comments
+1 I searched for about 1 hour why docker not use yarn 4.x.x... |
I agree this is a problem, we should release a patch in 1.22 that fixes that. I even had the idea of integrating the Corepack engine within the 1.22 release, so that even if Corepack isn't explicitly installed the
Perhaps not necessarily; I revived the thread on nodejs/docker-node#1768, we'll see if something comes out of that. In any case, I had little time to spend on Corepack lately as I was working on the 4.0 release, but now I think I'll focus a little more on it to bring it out of experimental. |
Awesome!
This would be a big help to people using older versions of Node. Less of a problem now that new LTS'es have been minted, but still helpful.
Nice - that would be great! Thanks for being so open to hearing me out on this problem. I think you'll have a lot of happy |
For those following this thread, it looks like Yarn Classic v1.22.20 and beyond now warn if the
Thanks, @arcanis, for this improvement! |
Weirdly I get this error message even if there is no |
People often run into issues with `yarn install` because they're using a newer yarn. The situation is generally bad - we don't want to update to Yarn v4 yet because it is marked experimental and is not the default yarn that gets installed by node currently. We could add a `packageManager` field to our package.json, but this will only fail the build with a better (hopefully) error message, and will necessitate the user to `corepack_enable`. I'm not sure what's the best approach right now to make the initial setup be seamless (I think we're using the approach that works for the maximum of all the alternatives, but I'm not sure). At least, let me add a note about it. Ref: * yarnpkg/berry#5912
Honestly I think it would be great if the latest version of Yarn Classic – whatever gets installed when you install Yarn with Homebrew or NPM or something like that – would always present a big "deprecated" warning whenever run, whether or not a |
Hi @camertron |
@Jolsty unfortunately it was long enough ago I don't remember. I think I ended up resetting everything by installing a different version of node. |
Solution for me for a mac user. I accidentaly created package.json to root. just delete node_modules package lock and package json from the path same as your .volta .yarn directory. |
for me deleting the package.json file from Users/username fixed the issue, it mentioned just this: "packageManager": "yarn@3.6.4", so removed the file and works |
Describe the user story
As a consultant working with many different companies and projects using
yarn
, it has been difficult to migrate from the "checked in Yarn version" (.yarnrc.yml
'syarnPath
setting) tocorepack
. When migrating tocorepack
, users who have not enabledcorepack
can accidentally use global Yarn Classic and they receive no warning about it.Checked In Yarn Version referenced by
yarnPath
I'm using
yarn set version 3.6.4
to show how this worked in Yarn Berry v3 when checking in the release to the repo.Source:
✅ Global Yarn Classic
✅ Corepack
root@2d0e84fe9c26:/test-project# corepack enable root@2d0e84fe9c26:/test-project# yarn --version 3.6.4
Corepack (v4 recommendation)
I'm only writing the
packageManager
key inpackage.json
. Currently,yarn set version <VERSION>
will only write thepackageManager
key if the local machine hascorepack
already enabled.Source:
❌ Global Yarn Classic
Even in the
test-project
, where thepackageManager
key is set toyarn@4.0.1
, globalyarn
still wins. This is different than the behavior when the release is checked in.✅ Corepack
However, if I enable
corepack
, the proper version is used.root@870c6624fa62:/test-project# corepack enable root@870c6624fa62:/test-project# yarn --version 4.0.1
The Issue
The main issues I see are:
packageManager
key will do the right thing. You have to extend the official image to remove global yarn and/or enablecorepack
.yarn set version <VERSION>
makes global assumptions based on one developer's machine. If I havecorepack
enabled and runyarn set version berry
,yarn
does not write the release to the repo. In this case,yarn
is making a global assumption that my CI environment, runtime container, other developer's machines, etc. will also havecorepack
enabled.packageManager
is set to a Yarn Berry version, Yarn Classic will run without warning or erroring. Most users will be unaware that there could be incompatibilities.corepack
to be enabled for each Node version. Sincecorepack enable
overwrites theyarn
binary, it must be run for each version of Node you have installed via a Node Version Manager. Therefore, when switching around between projects using different versions of Node, it's easy to forget that you need to runcorepack enable
. Since there's no warning, you can transparently/accidentally use globalyarn
instead of berry.I want to be able to guarantee that all consumers running
yarn
commands are using the proper version. It appears that Yarn Classic can read.yarnrc.yml
'syarnPath
config and always run the the correct version. However it does not pay attention to thepackageManager
key inpackage.json
.Describe the solution you'd like
A new release of Yarn Classic that throws an error if
package.json
'spackageManager
key is set, butcorepack
is not enabled. If the release is checked in and referenced byyarnPath
, thepackageManager
key is ignored.Describe the drawbacks of your solution
corepack
is enabled. There's nocorepack status
that easily verifies thatcorepack
is enabled (How can I detect if corepack is already enabled? nodejs/corepack#113).Describe alternatives you've considered
corepack
is not enabled, no matter the settings currently used. This doesn't help Classic users, though.package.json
'spackageManager
version and compares it against its own version. If there's a mismatch it refuses to run. Again, doesn't help Classic users..yarnrc.yml
that requirescorepack
to be enabled in v4 and newer. If.yarnrc.yml
'srequireCorepack
is set totrue
, we somehow verify for the user (see issue above RE: nocorepack status
command). Again, doesn't help Classic users.yarn
Classic binaries to be removed from the official Node image, and corepack to be enabled by default. Sincecorepack
is experimental, it feels like this will be a hard sell.corepack
), we should do our best to help people configure their environment.The text was updated successfully, but these errors were encountered: