Error: Cannot find module ‘/home/[username]/.yarn/releases/yarn-berry.cjs’

Ubuntu 20.04.01
Node v14.13.0
NPM 6.14.8

yarn, yarn --version or any yarn-related terminal command

What is the current behavior?
After installing yarn via the official installation tutorial on Ubuntu this error occurs:

  throw err;

Error: Cannot find module '/home/tafadzwa/.yarn/releases/yarn-berry.cjs'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
    at Function.Module._load (internal/modules/cjs/loader.js:747:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47 {
  requireStack: []

Running which yarn yields /usr/bin/yarn

What is the expected behavior?
yarn or yarn --version should output a version string

Steps to reproduce
Install yarn on the platform under Platform heading and type yarn --version

Any other information
Similar to #7948

1 possible answer(s) on “Error: Cannot find module ‘/home/[username]/.yarn/releases/yarn-berry.cjs’

  1. 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.