问题
- 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
- open terminal
- rm -rf node_modules yarn.lock yarn-error.log package-lock.json
- brew uninstall --force yarn
- npm uninstall -g yarn
- yarn -v
- which yarn
- rm -rf ~/.yarn (OPTIONAL, not recommended)
- rm -rf /usr/local/bin/yarn
- rm -rf /usr/local/bin/yarnpkg
- which yarn
NPM & NODE UNINSTALL:
- keep adding to terminal
- brew uninstall --force node
- brew cleanup
- sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/{npm*,node*,man1/node*}
- sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* /usr/local/lib/dtrace/node.d ~/.npm ~/.node-gyp
- sudo rm -rf /opt/local/bin/node /opt/local/include/node /opt/local/lib/node_modules
- sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node.1 /usr/local/lib/dtrace/node.d
- brew doctor
- brew cleanup --prune-prefix
INSTALL:
- same terminal
- brew install yarn
- brew install node
- brew link node
- sudo chmod 776 /usr/local/lib
- brew link --overwrite node
- sudo chmod 755 /usr/local/lib
- brew link node
- yarn policies set-version
- 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