corepack icon indicating copy to clipboard operation
corepack copied to clipboard

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\corepack\dist\yarn.js'

Open Pnlvfx opened this issue 2 months ago • 13 comments

I just upgraded to node 25 and the good news comes to me. Corepack is no more bundled inside nodejs.

After some research I found that I have to do: npm install -g corepack // extra corepack enable // as usual corepack use yarn@stable // as usual

the corepack use yarn@stable will work but then if I do:

yarn install

I get:

node:internal/modules/cjs/loader:1422 throw err; ^

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\corepack\dist\yarn.js' at Module._resolveFilename (node:internal/modules/cjs/loader:1419:15) at defaultResolveImpl (node:internal/modules/cjs/loader:1057:19) at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1062:22) at Module._load (node:internal/modules/cjs/loader:1225:37) at TracingChannel.traceSync (node:diagnostics_channel:328:14) at wrapModuleLoad (node:internal/modules/cjs/loader:244:24) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 { code: 'MODULE_NOT_FOUND', requireStack: [] }

Node.js v25.0.0

Pnlvfx avatar Oct 18 '25 20:10 Pnlvfx

@Pnlvfx

  • Which operating system are you working with?
  • How did you install Node.js 25?

MikeMcC399 avatar Oct 21 '25 13:10 MikeMcC399

having the same issue at the moment OS: Windows 11 Node JS: 25.0.0 corepack is installed under APPDATA but Node is looking for it under Program Files

ReutovIgorEndava avatar Oct 21 '25 14:10 ReutovIgorEndava

@ReutovIgorEndava

Please share how you installed Node.js 25.0.0 on your Windows 11 system.

MikeMcC399 avatar Oct 21 '25 14:10 MikeMcC399

corepack enable // as usual

That's not necessary btw, could you try without it?

aduh95 avatar Oct 21 '25 14:10 aduh95

it was installed through company portal which handles the installation of app at the company (sad story)

ReutovIgorEndava avatar Oct 21 '25 14:10 ReutovIgorEndava

@ReutovIgorEndava

it was installed through company portal which handles the installation of app at the company (sad story)

You may need to ask for assistance through your company support channel in that case, so that they can check whether their installation method supports using Corepack on Windows 11 with Node.js 25.

MikeMcC399 avatar Oct 21 '25 15:10 MikeMcC399

I also have this issue. I had Node.js installed via winget with default parameters (winget install OpenJS.NodeJS). I didn't use it much lately but regularly updated it via winget upgrade --all. Now it also throws this error:

PS C:\Users\eugen> yarn -v
node:internal/modules/cjs/loader:1422
  throw err;
  ^

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\corepack\dist\yarn.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1419:15)
    at defaultResolveImpl (node:internal/modules/cjs/loader:1057:19)
    at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1062:22)
    at Module._load (node:internal/modules/cjs/loader:1225:37)
    at TracingChannel.traceSync (node:diagnostics_channel:328:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:244:24)
    at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5)
    at node:internal/main/run_main_module:33:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v25.0.0

Windows 11. Re-installing didn't help

XFox111 avatar Oct 21 '25 15:10 XFox111

I fixed it by removing these files from C:\Program Files\nodejs:

yarn.CMD
yarn.ps1
yarn

XFox111 avatar Oct 21 '25 16:10 XFox111

@XFox111

winget installs a Node.js msi package. There are known issues with this configuration.

See the README comments:

If Corepack was installed on your system using a Node.js Windows Installer .msi package then you might need to remove it before attempting to install a different version of Corepack using npm. You can select the Modify option of the Node.js app settings to access the Windows Installer feature selection, and on the "corepack manager" feature of the Node.js .msi package by selecting "Entire feature will be unavailable". See Repair apps and programs in Windows for instructions on accessing the Windows apps page to modify settings.

  • and some more details in https://github.com/nodejs/corepack/issues/646

Anyway, it sounds like you already found a workaround.

I also noticed when I executed winget show OpenJS.NodeJS --versions that some versions are missing. For instance the latest 22.x version I found was 22.10.0 where I would expect to see 22.21.0 as the current LTS version.

EDIT: I researched and found that the LTS versions of Node.js, that are packaged by Microsoft, are installed with winget install OpenJs.NodeJS.LTS and they are not listed under OpenJS.NodeJS.

MikeMcC399 avatar Oct 21 '25 17:10 MikeMcC399

@MikeMcC399 oh, I see. The website didn't say anything about msi's, so I didn't think there's something wrong with them. Thanks!

XFox111 avatar Oct 21 '25 17:10 XFox111

for anyone facing this, I solved it by removing nodejs completely and install it again, the issue come from the fact that node try to run the old corepack (the integrated one) rather than the new one, so you delete node and then you go on your system node folder and delete it, then install node and the issue should be gone

Pnlvfx avatar Oct 21 '25 17:10 Pnlvfx

See also Microsoft's recommendations on how to install Node.js on Windows

https://learn.microsoft.com/en-us/windows/dev-environment/javascript/nodejs-on-windows

MikeMcC399 avatar Oct 22 '25 05:10 MikeMcC399

See also Microsoft's recommendations on how to install Node.js on Windows

https://learn.microsoft.com/en-us/windows/dev-environment/javascript/nodejs-on-windows

thanks for replying to me right away, I solved the issue almost 1 minute after opening it as I was suspecting that there were some left file on the node folder, honestly I always used chocolatey on win as I like the idea to have something like apt and I didn't find any issue so far.

feel free to close the issue if you want, i'll keep it open because maybe it can help someone facing the same issue, but if you want, you can close it

thanks 🙏

Pnlvfx avatar Oct 22 '25 16:10 Pnlvfx