Muhammad Lutfi Zaini
Muhammad Lutfi Zaini

Reputation: 11

I tried reinstalling yarn but after re-installing I found this problem, Error: Cannot find module '/home/fiii/.yarn/releases/yarn-1.22.17.cjs'

I tried reinstalling yarn but after re-installing I found this problem, I've tried searching the internet but haven't found a solution.

fiii@neo:~$ yarn --version
node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module '/home/fiii/.yarn/releases/yarn-1.22.17.cjs'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Upvotes: 1

Views: 566

Answers (1)

Gilberto Vásquez
Gilberto Vásquez

Reputation: 19

Tafadzwa Gonera answers this question quite helpfully here:

Running rm ~/.yarnrc and rm ~/.yarnrc.yml and worked for me. Don't worry if either file isn't there. ~/.yarnrc was not found in my case so I ended up deleting ~/.yarnrc.yml only. I logged out and in to the terminal and ran yarn --version and got 1.22.5

Why does this solution work?
When I ran npm install -g yarn or npm install -g yarn@berry yarnrc and/or yarnrc.yml were/was created with the yarnPath pointing to /home/[username]/.yarn/releases/yarn-berry.cjs. Running yarn --version would run a lookup for yarn-berry.cjs based on the yarnPath Since yarn-berry.cjs wasn't there the runtime would trigger an appropriate error hence it makes sense that removing yarnrc and/or yarnrc.yml solves the issue.

Upvotes: 2

Related Questions