`corepack preapre` : ENOENT: no such file or directory, stat
Environment
Windows with NVM (Node Version Manager) Node version : v18.14.2
Description
Trying to install the stable version of yarn return an error
Command to reproduce the issue
corepack prepare yarn@stable
Output error
Internal Error: ENOENT: no such file or directory, stat '{COREPACK_HOME}\yarn\3.4.1'
Error: ENOENT: no such file or directory, stat '{COREPACK_HOME}\yarn\3.4.1'
More information about error
By looking for the root cause of the error, I was able to find at which statement the error occurs The error occurs when installing Yarn intending to rename the temporary folder
- Into the file corepackUtils.ts
-
installVersionfunction - On
renamestatementawait fs.promises.rename(tmpFolder, installFolder);
[Error: EPERM: operation not permitted, rename '{COREPACK_HOME}\corepack-35332-42750715.c38c6' -> '{COREPACK_HOME}\yarn\3.4.1'] {
errno: -4048,
code: 'EPERM',
syscall: 'rename',
path: '{COREPACK_HOME}\\corepack-35332-42750715.c38c6',
dest: '{COREPACK_HOME}\\yarn\\3.4.1'
}
Workaound
I tried to force the closing/destruction of streams but it not working.
On the other hand, by adding a delay just before the renaming, it worked
Here the delay statement : await new Promise(resolve => setTimeout(resolve, 100));
Note: you can also rename manually the tmp directory and move to the install folder (ex '{COREPACK_HOME}\corepack-35332-42750715.c38c6' -> '{COREPACK_HOME}\yarn\3.4.1')
Windows is a little weird, I think it sometimes locks files just after their creation for "malicious file analysis" 🙁
Environment Windows 11 with NVM 1.1.9 Node version : v18.14.0
I followed the yarn 2+ installation doc and ran into the same situation.
thanks to ShiJuuRoku's information about error, I rename the tmpFolder which appeared after I ran sudo corepack prepare yarn@stable --activate to installFolder and move it to correct place to workaround it
This is pretty bad, as it essentially prevents corepack from functioning at all on Windows (with certain security software?). Maybe you could just run a loop on windows and wait until the file can be moved (only EPERM) or a timeout occurs.
This is a pretty annoying problem for us.
We execute yarn set version latest on our CI and every time yarn updates, we have to use an internal ticket for an admin to rename the folder on our servers.
The problem exists with Trend and Cortex XDR.
If the rename fails, we could try again after a delay, hopefully that would workaround the issue. PRs welcome.
I implemented the "workaround" and put it into a pull request #398