'Yarn installs, but all commands return MODULE_NOT_FOUND code

The link below doesn't answer my question

Issue reinstalling yarn - code: 'MODULE_NOT_FOUND'

I get an error trying to run yarn on it's own or with a command

➜  ~ brew install yarn
Error: homebrew-core is a shallow clone. To `brew update` first run:
  git -C "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core" fetch --unshallow
This restriction has been made on GitHub's request because updating shallow
clones is an extremely expensive operation due to the tree layout and traffic of
Homebrew/homebrew-core. We don't do this for you automatically to avoid
repeatedly performing an expensive unshallow operation in CI systems (which
should instead be fixed to not use shallow clones). Sorry for the inconvenience!
==> Downloading https://yarnpkg.com/downloads/1.22.10/yarn-v1.22.10.tar.gz
Already downloaded: /Users/meepy/Library/Caches/Homebrew/downloads/1ed0a9b4d5234a1301d4f37d98ad9866a1695d91581d6020ea551b5af4d1b888--yarn-v1.22.10.tar.gz
🍺  /usr/local/Cellar/yarn/1.22.10: 15 files, 5MB, built in 2 seconds
➜  ~ yarn
node:internal/modules/cjs/loader:928
  throw err;
  ^

Error: Cannot find module '/Users/meepy/.yarn/releases/yarn-1.22.5.cjs'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:925:15)
    at Function.Module._load (node:internal/modules/cjs/loader:769:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

I tried reinstalling with:

brew uninstall --force yarn
rm -rf /usr/local/bin/yarn
rm -rf /usr/local/bin/yarnpkg
brew install yarn

Environment

  • Node Version: v15.4.0
  • Yarn v1 Version: 1.22.5
  • OS and version: macOS Big Sur (11.0.1)


Solution 1:[1]

Make sure you don't have a .yarnrc file either in your local or user directory that has a yarn-path entry (pointed to where it's looking).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Francis Upton IV