Skip to content

corepack preapre : ENOENT: no such file or directory, stat #246

Closed

Description

@ShiJuuRoku

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')

Activity

  1. arcanis commented on Mar 4, 2023

    @arcanis
    Contributor

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

  2. DryverStudio commented on Mar 21, 2023

    @DryverStudio

    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

  3. megla-tlanghorst commented on May 23, 2023

    @megla-tlanghorst

    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.

  4. tisonv commented on Aug 28, 2023

    @tisonv

    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.

  5. aduh95 commented on Sep 18, 2023

    @aduh95
    Contributor

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

  6. ngnlTeto commented on Feb 26, 2024

    @ngnlTeto
    Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions