I just came back to work on a React project after working in the Rails environment and found that I cannot run any NPM commands in my Mac terminal.
(在Rails环境中工作后,我回到了React项目上,发现无法在Mac终端中运行任何NPM命令。)
I've tried all the remedies that I have come across but none have worked.(我已经尝试了所有遇到的补救措施,但是都没有奏效。)
The bigger issue is what caused this and how can I avoid it again.(更大的问题是造成此问题的原因以及如何再次避免它。)
Here is the error.
(这是错误。)
What do I need to do?(我需要做什么?)
Please help.(请帮忙。)
$npm install
internal/modules/cjs/loader.js:550
throw err;
^
Error: Cannot find module '../lib/utils/unsupported.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:548:15)
at Function.Module._load (internal/modules/cjs/loader.js:475:25)
at Module.require (internal/modules/cjs/loader.js:598:17)
at require (internal/modules/cjs/helpers.js:11:18)
at /usr/local/lib/node_modules/npm/bin/npm-cli.js:19:21
at Object.<anonymous> (/usr/local/lib/node_modules/npm/bin/npm-cli.js:92:3)
at Module._compile (internal/modules/cjs/loader.js:654:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
at Module.load (internal/modules/cjs/loader.js:566:32)
at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
I have tried the following:
(我尝试了以下方法:)
$brew update
$brew uninstall node
$brew install node
After which the following commands come up as so when $which npm was unknown command before:
(在此之后,以下命令将出现:$哪个npm是之前未知的命令:)
$which npm
/usr/local/bin/npm
$which node
/usr/local/bin/node
I even tried running:
(我什至尝试运行:)
/usr/local/bin/npm -v
but get the same error as above while
(但同时获得与上述相同的错误)
/usr/local/bin/node -v
v9.11.1
works fine.
(工作正常。)
added the following to my .zshrc file:
(在我的.zshrc文件中添加了以下内容:)
export PATH=/usr/local/bin/node:$PATH
export PATH=/usr/local/bin/npm:$PATH
I have also tried:
(我也尝试过:)
$brew uninstall --force node
$brew link --overwrite node
Warning: Already linked: /usr/local/Cellar/node/9.11.1
To relink: brew unlink node && brew link node
$rm -rf /usr/local/lib/node_modules/npm
then,
(然后,)
$node install
but that does not work, either.
(但这也不起作用。)
$echo $NODE_PATH
does come up empty, so I may need to added the following to my .bashrc.
(确实是空的,因此我可能需要将以下内容添加到我的.bashrc中。)
export PATH="/usr/local/bin/npm:/usr/local/bin/node:/usr/local/bin:$PATH"
That does not work either.
(那也不行。)
ask by bigmugcup translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…