Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

corepack won't install yarn #178

Open
jetersen opened this issue Sep 8, 2022 · 14 comments
Open

corepack won't install yarn #178

jetersen opened this issue Sep 8, 2022 · 14 comments

Comments

@jetersen
Copy link

jetersen commented Sep 8, 2022

$ 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
@arcanis
Copy link
Contributor

arcanis commented Sep 8, 2022

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

@aduh95
Copy link
Contributor

aduh95 commented Sep 8, 2022

What version of Corepack are you using?

@jetersen
Copy link
Author

jetersen commented Sep 8, 2022

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

Version is

$ corepack --version
0.12.1

@aduh95
Copy link
Contributor

aduh95 commented Sep 8, 2022

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?

@jetersen
Copy link
Author

jetersen commented Sep 8, 2022

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
Copy link
Author

jetersen commented Sep 8, 2022

$ 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

@aaryg
Copy link

aaryg commented Sep 27, 2022

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

@NightWatchman
Copy link

NightWatchman commented Nov 4, 2022

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?

@ChillyBots
Copy link

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

@thomascallahan
Copy link

thomascallahan commented Dec 4, 2022

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?

@v1nc3n4
Copy link

v1nc3n4 commented Dec 28, 2022

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

@nlxdodge
Copy link

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.

@fengyuanchen
Copy link

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.

@rafalkrupinski
Copy link

rafalkrupinski commented Apr 2, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests