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. 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.
在Rails环境中工作后,我刚刚回到React项目工作,发现我不能在Mac终端上运行任何NPM命令。我已经尝试了我所遇到的所有补救措施,但没有一个奏效。更大的问题是造成这种情况的原因以及我如何才能再次避免它。
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:
之后,当$which 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.
这也不起作用。
4 个解决方案
#1
3
- Uninstall node
brew uninstall node
- 卸载节点brew卸载节点
- Then, install node from the website
- 然后,从网站上安装节点
#2
1
I had an issue after upgrade my mac. I tried different solutions available on stack overflow and nothing work for me.
我在升级mac后遇到了一个问题。我尝试了不同的解决方案来解决栈溢出问题,但对我来说毫无用处。
This solution works for me.
这个解决方案对我有效。
- Uninstall node all version
brew uninstall --force node
- 卸载节点所有版本brew卸载——强制节点
- Install it again by this
brew install node
- 通过这个brew安装节点再次安装它
First point remove all node versions if available.
第一点删除所有可用的节点版本。
Done. Enjoy coding.
完成了。喜欢编程。
#3
0
Try this one: https://gist.github.com/DanHerbert/9520689
试试这个:https://gist.github.com/DanHerbert/9520689
"If you're a Homebrew user and you installed node via Homebrew, there is a major philosophical issue with the way Homebrew and NPM work together."
“如果你是一个自制的用户,并且你通过自制程序安装了node,那么就有一个重要的哲学问题,那就是Homebrew和NPM合作的方式。”
Kudos to Dan Herbert for the solution.
感谢丹·赫伯特的解决方案。
#4
-1
I had the same error after brew upgrade
on mac. I did brew postinstall node
and that fixed it.
我在brew upgradeon mac之后也犯了同样的错误。
#1
3
- Uninstall node
brew uninstall node
- 卸载节点brew卸载节点
- Then, install node from the website
- 然后,从网站上安装节点
#2
1
I had an issue after upgrade my mac. I tried different solutions available on stack overflow and nothing work for me.
我在升级mac后遇到了一个问题。我尝试了不同的解决方案来解决栈溢出问题,但对我来说毫无用处。
This solution works for me.
这个解决方案对我有效。
- Uninstall node all version
brew uninstall --force node
- 卸载节点所有版本brew卸载——强制节点
- Install it again by this
brew install node
- 通过这个brew安装节点再次安装它
First point remove all node versions if available.
第一点删除所有可用的节点版本。
Done. Enjoy coding.
完成了。喜欢编程。
#3
0
Try this one: https://gist.github.com/DanHerbert/9520689
试试这个:https://gist.github.com/DanHerbert/9520689
"If you're a Homebrew user and you installed node via Homebrew, there is a major philosophical issue with the way Homebrew and NPM work together."
“如果你是一个自制的用户,并且你通过自制程序安装了node,那么就有一个重要的哲学问题,那就是Homebrew和NPM合作的方式。”
Kudos to Dan Herbert for the solution.
感谢丹·赫伯特的解决方案。
#4
-1
I had the same error after brew upgrade
on mac. I did brew postinstall node
and that fixed it.
我在brew upgradeon mac之后也犯了同样的错误。