Search code examples
node.jsyarnpkgnvm

How can I restore Yarn after accidentally deleting the .yarn folder?


After unintentionally deleting the .yarn folder in my home directory, I encountered an error when trying to run the yarn command:

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

Error: Cannot find module '/home/user/.yarn/releases/yarn-1.22.22.cjs'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1142:15)
    at Module._load (node:internal/modules/cjs/loader:983:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:142:12)
    at node:internal/main/run_main_module:28:49 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v21.7.3

I attempted to completely uninstall Yarn from my machine by removing it using the package manager with pacman -R yarn, and also via npm with npm uninstall -g yarn. Despite reinstalling it afterward, the error persists. Additionally, I tried removing Corepack and Node.js and reinstalling them, but this did not resolve the issue.


Solution

  • The problem was resolved by deleting the .yarnrc file!