Issue reinstalling yarn - code: 'MODULE_NOT_FOUND'

天大地大妈咪最大 提交于 2021-01-29 08:20:41

问题


  • Node.js Version:14.0.0
  • OS: MacOS 10.15.4
  • Scope (install, code, runtime, meta, other?): Yarn install
  • Module (and version) (if relevant): internal/modules/cjs/loader.js

Upon running any Yarn command, I get the following error. This is after reinstalling and following this sequence of commands:


YARN UNINSTALL:

yarn cache clean

  1. open terminal
  2. rm -rf node_modules yarn.lock yarn-error.log package-lock.json
  3. brew uninstall --force yarn
  4. npm uninstall -g yarn
  5. yarn -v
  6. which yarn
  7. rm -rf ~/.yarn (OPTIONAL, not recommended)
  8. rm -rf /usr/local/bin/yarn
  9. rm -rf /usr/local/bin/yarnpkg
  10. which yarn

NPM & NODE UNINSTALL:

  1. keep adding to terminal
  2. brew uninstall --force node
  3. brew cleanup
  4. sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/{npm*,node*,man1/node*}
  5. sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* /usr/local/lib/dtrace/node.d ~/.npm ~/.node-gyp
  6. sudo rm -rf /opt/local/bin/node /opt/local/include/node /opt/local/lib/node_modules
  7. sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node.1 /usr/local/lib/dtrace/node.d
  8. brew doctor
  9. brew cleanup --prune-prefix

INSTALL:

  1. same terminal
  2. brew install yarn
  3. brew install node
  4. brew link node
  5. sudo chmod 776 /usr/local/lib
  6. brew link --overwrite node
  7. sudo chmod 755 /usr/local/lib
  8. brew link node
  9. yarn policies set-version
  10. n 12.13.1

    11. yarn -v && node -v && npm -v

Then the following appears on terminal upon running yarn command at step 9 of the install:

USER-MacBook-Pro:~ User$ yarn
internal/modules/cjs/loader.js:1017
  throw err;
  ^

Error: Cannot find module '/Users/jlagos/.yarn/releases/yarn-1.21.1.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1014:15)
    at Function.Module._load (internal/modules/cjs/loader.js:884:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ ]
}

Any help on how to restore Yarn? Seems like node is keeping track of a previous yarn version.


回答1:


I keep running into the same issue whenever I update yarn as well. Something possibly in the (currently unseen) $PATH that I've yet to be able to remove.

As @jlagos pointed out, you can trick the system to run the latest version instead of 1.21.1 by copying over the latest over that location.

If you have yet to install or see yarn at /.yarn/ you can install it directly following https://classic.yarnpkg.com/en/docs/install/ or

curl -o- -L https://yarnpkg.com/install.sh | bash

Then create and copy of the file location with the following:

mkdir ~/.yarn/releases/
cp ~/.yarn/lib/cli.js ~/.yarn/releases/yarn-1.21.1.js

yarn --version

When running yarn, it should now state the latest (such as 1.22.5 at the time of writing).




回答2:


Turns out manually creating the directory /releases/ and duplicating the cli.js file from /.yarn/lib/ and renaming the duplicate to yarn-1.21.1.js was the solution to this issue. Leaving this here for future reference.

Also, at first I couldn't find the /.yarn/ directory, but installing directly from yarn did the trick, using the following:




来源:https://stackoverflow.com/questions/61513601/issue-reinstalling-yarn-code-module-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!