corepack icon indicating copy to clipboard operation
corepack copied to clipboard

`corepack preapre` : ENOENT: no such file or directory, stat

Open ShiJuuRoku opened this issue 2 years ago • 5 comments

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

  1. Into the file corepackUtils.ts
  2. installVersion function
  3. On rename statement await 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')

ShiJuuRoku avatar Mar 03 '23 23:03 ShiJuuRoku

Windows is a little weird, I think it sometimes locks files just after their creation for "malicious file analysis" 🙁

arcanis avatar Mar 04 '23 06:03 arcanis

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

Renhz avatar Mar 21 '23 07:03 Renhz

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.

megla-tlanghorst avatar May 23 '23 14:05 megla-tlanghorst

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.

tisonv avatar Aug 28 '23 06:08 tisonv

If the rename fails, we could try again after a delay, hopefully that would workaround the issue. PRs welcome.

aduh95 avatar Sep 18 '23 08:09 aduh95

I implemented the "workaround" and put it into a pull request #398

ngnlTeto avatar Feb 26 '24 10:02 ngnlTeto