corepack
corepack copied to clipboard
Yarn version folder not found when trying to set version while corepack is enabled
OS: Windows 11 Node.js v18.19.0, installed via Windows installer Yarn v1.22.21 installed globally via npm
Steps:
- Open terminal as admin and run
enable corepack
- Navigate to existing yarn project folder or create new with
yarn init
- 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.
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.
I get the same error when running corepack use yarn@stable
. It also creates the corepack-{someidentifer}
folder same way.
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.
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
thencorepack disable
(it creates the folderC:\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 directory4.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 ;)
@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.
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
thencorepack disable
(it creates the folderC:\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 directory4.0.2
and paste the two filesin 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.2You're good ;)
This worked for me though thanks
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
thencorepack disable
(it creates the folderC:\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 directory4.0.2
and paste the two filesin 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.2You'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.
Is the cause for this known? Could it be a permissions or folder ownership issue? I haven't been able to solve it on my end, other than using the manual workaround. I was fine working around it every so often, but now I have coworkers facing the same issues and would benefit from identifying the cause.
Is the cause for this known? Could it be a permissions or folder ownership issue? I haven't been able to solve it on my end, other than using the manual workaround. I was fine working around it every so often, but now I have coworkers facing the same issues and would benefit from identifying the cause.
Users typically have full access to %LOCALAPPDATA% so it's unlikely to be a permissions issue.