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

Yarn version folder not found when trying to set version while corepack is enabled #334

Open
MrJonez77 opened this issue Dec 6, 2023 · 7 comments

Comments

@MrJonez77
Copy link

OS: Windows 11
Node.js v18.19.0, installed via Windows installer
Yarn v1.22.21 installed globally via npm

Steps:

  1. Open terminal as admin and run enable corepack
  2. Navigate to existing yarn project folder or create new with yarn init
  3. Run yarn set version berry and you get following kind of error:
    Internal Error: ENOENT: no such file or directory, stat 'C:\Users\{username}\AppData\Local\node\corepack\yarn\4.0.2'

When you go check C:\Users\{username}\AppData\Local\node\corepack\yarn there is only folder for version 1.22.21 but not for 4.0.2 which explains the error. When you navigate to C:\Users\{username}\AppData\Local\node\corepack\ a new folder corepack-{someidentifer} has been created there. It seems to contain the yarn.js needed but is in the wrong place?

Any ideas what is causing this behavior? Way around it is to disable corepack and let yarn set version to download yarn binary for the project itself. However, Yarn nowadays recommends to use Corepack so I'd prefer using that if possible. Another workaround is to modify the corepack folders in local appdata but that is just treating the symptoms, not fixing the cause.

@aduh95
Copy link
Contributor

aduh95 commented Dec 6, 2023

I think you'd get better result with corepack use yarn@stable instead of yarn set version berry.

Any ideas what is causing this behavior?

It looks more like a Yarn bug, the command must have some assumption that are not correct when using Corepack? Not sure, maybe you should report that issue to them.

@MrJonez77
Copy link
Author

I get the same error when running corepack use yarn@stable. It also creates the corepack-{someidentifer} folder same way.

@Senedac
Copy link

Senedac commented Dec 13, 2023

Facing the exact same issue as MrJonez77.
Also on windows 11 but tried it with node 20.10.0.
Experimented with yarn 1.22.21 and 4.0.2. Tried changing to version 4.0.0.

@L4m3-DucK
Copy link

L4m3-DucK commented Jan 23, 2024

I propose a 'manual' workaround that works :

  • install node 18.x or 20.x or 21.x (I have tested only in 21.x version) with windows installer
  • in an admin console powershell do corepack enable then corepack disable (it creates the folder C:\Users\{username}\AppData\Local\node\corepack)
  • Open a Windows Explorer and go to the folder C:\Users\{username}\AppData\Local\node\corepack
  • Here you can find some directory named corepack-xxxx-xxxxxxxxxx, open one of it and copy the two files (yarn.js and .corepack) (.corepack is mandatory otherwise the folder yarn is going to be empty by corepack)
  • Open the directory C:\Users\{username}\AppData\Local\node\corepack\yarn, create a new directory 4.0.2 and paste the two files
  • in an admin console powershell do corepack enable
  • in a non-admin console powershell, in your project directory do
    • corepack prepare yarn@stable --activate
    • yarn -v --> 4.0.2

You're good ;)

@DiskCrasher
Copy link

DiskCrasher commented Jan 31, 2024

@L4m3-DucK This didn't quite work for me, but my config was a little different from the OP (same problem though). Firstly, there were more than just two files in the corepack-xxxx-xxxxxxxxxx folder and by looking at the package.json file mine were for v1.22.21. I copied them over to a yarn\v1.22.21 folder and was then able to run yarn -v and see it output v1.22.21. But when I followed the rest of your steps and ran corepack prepare yarn@stable --activate I got the ENOENT error stating it couldn't find a v4.1.0 directory. So I copied over the new corepack-xxxx-xxxxxxxxxx to a yarn\4.1.0 folder at which point yarn -v output v4.1.0.

Definitely something amiss here. Seems like new versions aren't getting installed into the %LOCALAPPDATA%\node\corepack\yarn directory like they should. Prior to this I had even uninstalled Node.js, manually deleted all the yarn and npm folders I could find, and reinstalled Node.js. Still didn't work.

@rajashree23
Copy link

I propose a 'manual' workaround that works :

  • install node 18.x or 20.x or 21.x (I have tested only in 21.x version) with windows installer

  • in an admin console powershell do corepack enable then corepack disable (it creates the folder C:\Users\{username}\AppData\Local\node\corepack)

  • Open a Windows Explorer and go to the folder C:\Users\{username}\AppData\Local\node\corepack

  • Here you can find some directory named corepack-xxxx-xxxxxxxxxx, open one of it and copy the two files (yarn.js and .corepack) (.corepack is mandatory otherwise the folder yarn is going to be empty by corepack)

  • Open the directory C:\Users\{username}\AppData\Local\node\corepack\yarn, create a new directory 4.0.2 and paste the two files

  • in an admin console powershell do corepack enable

  • in a non-admin console powershell, in your project directory do

    • corepack prepare yarn@stable --activate
    • yarn -v --> 4.0.2

You're good ;)

This worked for me though thanks

@kvanderhaeghen-aleacsysonline
Copy link

I propose a 'manual' workaround that works :

  • install node 18.x or 20.x or 21.x (I have tested only in 21.x version) with windows installer

  • in an admin console powershell do corepack enable then corepack disable (it creates the folder C:\Users\{username}\AppData\Local\node\corepack)

  • Open a Windows Explorer and go to the folder C:\Users\{username}\AppData\Local\node\corepack

  • Here you can find some directory named corepack-xxxx-xxxxxxxxxx, open one of it and copy the two files (yarn.js and .corepack) (.corepack is mandatory otherwise the folder yarn is going to be empty by corepack)

  • Open the directory C:\Users\{username}\AppData\Local\node\corepack\yarn, create a new directory 4.0.2 and paste the two files

  • in an admin console powershell do corepack enable

  • in a non-admin console powershell, in your project directory do

    • corepack prepare yarn@stable --activate
    • yarn -v --> 4.0.2

You're good ;)

I wanted it on 4.1.0. So the method worked to get it set to 4.0.2 (because I had a 4.0.2 directory in corepack/yarn), but I had to use yarn set version 4.1.0 in the non-admin powershell afterward. Then when I did yarn -v I got the correct version. You can also open .corepack to see which version of yarn it holds. This can help creating the directory for yarn.js and .corepack.

So thanks for the help! Hope this gets fixed soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants