corepack icon indicating copy to clipboard operation
corepack copied to clipboard

corepack won't install yarn

Open jetersen opened this issue 3 years ago • 14 comments

$ corepack prepare yarn@stable --activate
Preparing yarn@stable for immediate activation...
Internal Error: ENOENT: no such file or directory, stat 'C:\Users\jop\.node\corepack\yarn\3.2.3'
Error: ENOENT: no such file or directory, stat 'C:\Users\jop\.node\corepack\yarn\3.2.3'

After seeing this error, I tried to assist it by making the directory but yarn.js is not found

$ New-Item -ItemType Directory -Force C:\Users\jop\.node\corepack\yarn\3.2.3
$ corepack prepare yarn@stable --activate
Preparing yarn@stable for immediate activation...
$ yarn
Internal Error: Cannot find module 'C:\Users\jop\.node\corepack\yarn\3.2.3\yarn.js'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:956:15)
    at Module.loadMainModule (C:\Program Files\nodejs\node_modules\corepack\dist\corepack.js:16234:70)
    at Module.runVersion (C:\Program Files\nodejs\node_modules\corepack\dist\corepack.js:15878:52)
    at executePackageManagerRequest (C:\Program Files\nodejs\node_modules\corepack\dist\corepack.js:16123:62)
    at async BinaryCommand.validateAndExecute (C:\Program Files\nodejs\node_modules\corepack\dist\corepack.js:12484:26)
    at async Cli.run (C:\Program Files\nodejs\node_modules\corepack\dist\corepack.js:12145:24)
    at async main (C:\Program Files\nodejs\node_modules\corepack\dist\corepack.js:16163:16)
$ corepack prepare pnpm@latest --activate
Preparing pnpm@latest for immediate activation...
$ pnpm
Version 7.11.0

jetersen avatar Sep 08 '22 11:09 jetersen

That's strange, I don't repro it 🤔

arcanis avatar Sep 08 '22 12:09 arcanis

What version of Corepack are you using?

aduh95 avatar Sep 08 '22 13:09 aduh95

I used winget install OpenJS.NodeJS.LTS and ran corepack enable

Version is

$ corepack --version
0.12.1

jetersen avatar Sep 08 '22 15:09 jetersen

On more recent versions, we've switched the default COREPACK_HOME from the user home directory to the AppData one, which might help if you're seeing this because of a permission issue. Maybe you could try to upgrade Corepack to see if that solves it?

aduh95 avatar Sep 08 '22 15:09 aduh95

To upgrade from windows install with machine wide nodejs... I wonder if I can setup winget to install nodejs inside appdata.

I use gsudo to run as elevated user

$ $ENV:NPM_CONFIG_PREFIX="C:\Program Files\nodejs"
$ sudo npm install -g corepack

jetersen avatar Sep 08 '22 15:09 jetersen

$ corepack prepare yarn@stable --activate
Preparing yarn@stable for immediate activation...
Internal Error: ENOENT: no such file or directory, stat 'C:\Users\jop\AppData\Local\node\corepack\yarn\3.2.3'
Error: ENOENT: no such file or directory, stat 'C:\Users\jop\AppData\Local\node\corepack\yarn\3.2.3'

$ corepack --version
0.14.0

jetersen avatar Sep 08 '22 16:09 jetersen

I had this issue as well, trying to install yarn 3.1.1 on windows.

Corepack version 0.14.0

My workaround was to create the 3.1.1 folder in AppData\Local\node\corepack\yarn, and then download the yarn.js file manually there from https://repo.yarnpkg.com/3.1.1/packages/yarnpkg-cli/bin/yarn.js

aaryg avatar Sep 27 '22 16:09 aaryg

I am currently having this issue on corepack v0.14.2.

PS C:\Windows\system32> corepack enable
PS C:\Windows\system32> corepack prepare yarn@stable --activate
Preparing yarn@stable for immediate activation...
Internal Error: ENOENT: no such file or directory, stat 'C:\Users\{redacted}\AppData\Local\node\corepack\yarn\3.2.4'
Error: ENOENT: no such file or directory, stat 'C:\Users\{redacted}\AppData\Local\node\corepack\yarn\3.2.4'
PS C:\Windows\system32> corepack --version
0.14.2

Also, I am trying to set up a build server and I'm concerned that using the user's appdata folder will be problematic if the build process doesn't use the logged in user.

Perhaps it would be a good idea to consider using a location like the one returned by System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonApplicationData) in .NET?

NightWatchman avatar Nov 04 '22 19:11 NightWatchman

Same issue with corepack --version: 0.14.2 and a fresh install of node v18.12.1

ChillyBots avatar Nov 19 '22 17:11 ChillyBots

Same here. Windows 11, Corepack 0.14.1, fresh Node 16.18.1 install, trying to install Yarn 3.

> corepack prepare yarn@stable --activate
Preparing yarn@stable for immediate activation...
Internal Error: ENOENT: no such file or directory, stat 'C:\Users\tom\AppData\Local\node\corepack\yarn\3.3.0'
Error: ENOENT: no such file or directory, stat 'C:\Users\tom\AppData\Local\node\corepack\yarn\3.3.0'

There is a "1.22.19" directory from having run corepack enable -all in an attempt to fix this. It's like the attempt to install yarn 3 doesn't actually download it before trying to activate it? After trying @aaryg's workaround above, it seems to have worked. So it's not the activation process that fails, it's the download?

thomascallahan avatar Dec 04 '22 01:12 thomascallahan

Hi all,

I encountered a similar issue with NPM and tried to identify a way to reproduce it.

Environment:

  • Windows 10 64 bits
  • No node executable accessible with the PATH environment variable.

Project: directory containing only a package.json file.

{
  "packageManager": "[email protected]"
}

Basically, here's what I do:

  1. Remove any %USERPROFILE%\.node directory.
  2. Install Node.js in a new directory.
  3. Open a command prompt cmd in the project directory.
  4. Add the Node.js install directory to the PATH environment variable.
  5. Show Node version: node -v
  6. Enable NPM support through Corepack: corepack enable npm
  7. Show NPM version: npm -v
  8. Show again NPM version: npm -v

Results:

Internal Error: ENOENT: no such file or directory, stat 'C:\Users\<username>\.node\corepack\npm\6.14.17' Error: ENOENT: no such file or directory, stat 'C:\Users\<username>\.node\corepack\npm\6.14.17'

However, command 8 successfully returns 6.14.17.

Please find enclosed output with each Node.js/Corepack distribution. It seems the issue is also present with Node 18 distributions.

Thanks in advance for your help! BR

node-16.16.0-output.log node-16.17.0-output.log

EDIT:

Not sure it is relevant, but I forgot to mention that my %USERPROFILE% environment variable contains a space: C:\Users\Firstname Lastname

v1nc3n4 avatar Dec 28 '22 11:12 v1nc3n4

If I manually go to \AppData\Local\node\corepack and go the the downloaded folder. Create the yarn/3.4.1/ folder myself and put the downloaded folder there, then the next run of the command will work and Yarn now works on my machine again.

nlxdodge avatar Feb 21 '23 08:02 nlxdodge

A workable workaround from #246 for Windows users:

  1. Open C:\Program Files\nodejs\node_modules\corepack\dist\lib\corepack.cjs file.
  2. Search this line: await import_fs2.default.promises.rename(tmpFolder, installFolder). If not found, try to search rename(tmpFolder, installFolder).
  3. Add a new line await new Promise(resolve => setTimeout(resolve, 100)); before to the found line in setp 2.
  4. Save the file.
  5. Run the upgrade command: corepack prepare yarn@stable --activate.
  6. Check the version: yarn -v.

fengyuanchen avatar Aug 30 '23 08:08 fengyuanchen

I had this problem. The culprit was ~/.yarnrc.yml with path to old yarn installation.

Corepack was properly installing yarn, but then it tried to use that old version.

rafalkrupinski avatar Apr 02 '24 18:04 rafalkrupinski