yarnpkg / berry

📦🐈 Active development trunk for Yarn ⚒
https://yarnpkg.com
BSD 2-Clause "Simplified" License
7.45k stars 1.11k forks source link

[Bug?]: "Your application tried to access corepack" when running yarn on Windows #5956

Closed djflorio closed 1 year ago

djflorio commented 1 year ago

Self-service

Describe the bug

I'm on Windows 11, and using nvm-windows to manage my node version. EDIT: I completely removed nvm-windows and installed node 20.9.0 directly, and this same issue is happening, so this isn't related to nvm-windows.

When setting up a nextjs project using yarn berry, I get this error:

Internal Error: Your application tried to access corepack, but it isn't declared in your dependencies; this makes the require call ambiguous and unsound.

Required package: corepack (via "corepack\package.json") Required by: C:\Users\######\AppData\Roaming\nvm\v18.16.0\node_modules\corepack\dist\

Require stack:

  • C:\Users\######\AppData\Roaming\nvm\v18.16.0\node_modules\corepack\dist\corepack.js
  • C:\Users\######\AppData\Roaming\nvm\v18.16.0\node_modules\corepack\dist\yarn.js

Required package: corepack (via "corepack\package.json") Required by: C:\Users\######\AppData\Roaming\nvm\v18.16.0\node_modules\corepack\dist\

I also have a project using yarn berry that works fine my mac (which uses regular nvm), but when I try to build it on this Windows machine, the above error occurs.

To reproduce

On a Windows 11 machine using nvm-windows. Node version set to 18.16.0 or above.

Create an empty folder, then: corepack enable yarn set version berry (currently 4.0.1) yarn init -2 yarn dlx create-next-app@latest test

Environment

System:
    OS: Windows 11 10.0.22621
    CPU: (16) x64 12th Gen Intel(R) Core(TM) i7-1260P
Binaries:
    Node: 18.16.0 - C:\Users\######\AppData\Local\Temp\xfs-8c49319b\node.CMD

Additional context

No response

djflorio commented 1 year ago

yarn add corepack fixes the problem. I'm just not sure if this is supposed to be necessary.

However, a similar issue happens when I run yarn dlx @yarnpkg/sdks vscode to set up vscode for pnp. I get:

Error: Your application tried to access color-convert, but it isn't declared in your dependencies; this makes the require call ambiguous and unsound.

Required package: color-convert Required by: C:\Users\######\AppData\Local\Yarn\Berry\cache\ansi-styles-npm-4.3.0-245c7d42c7-10.zip\node_modules\ansi-styles\

djflorio commented 1 year ago

Solved after looking at #5699

Somehow I managed to accidentally generate a .pnp.cjs file in my HOME folder. After removing that, things started working as expected.

evguu commented 1 month ago

For anyone who finds this issue in search results and is as unobservant as me, let me reiterate the point from the comment above:

Check if you have a .pnp.cjs file in your HOME folder. If you do, remove it.