[英]After $npm install, Getting Error: Cannot find module '../lib/utils/unsupported.js'
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:之后,当 $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.那也行不通。
brew uninstall --force node
brew uninstall --force node
/usr/local/lib/node_modules
folder/usr/local/lib/node_modules
文件夹brew install node
brew install node
Assume this happens on MacOS, below solution works for me.假设这发生在 MacOS 上,下面的解决方案对我有用。
This happened to me after installing yarn.安装纱线后,这发生在我身上。
in a terminal:在终端中:
brew uninstall --force --ignore-dependencies node
brew install node
if you have trouble symlinking node, in the same terminal:如果您在符号链接节点时遇到问题,请在同一终端中:
sudo chown -R `whoami`:admin /usr/local/include
sudo chown -R `whoami`:admin /usr/local/bin
sudo chown -R `whoami`:admin /usr/local/share
sudo chown -R `whoami`:admin /usr/local/lib
brew link --overwrite node
Check that your re-installation worked by typing the following in the terminal:通过在终端中键入以下内容来检查您的重新安装是否有效:
node -v
I had an issue after upgrade my mac.升级我的 mac 后我遇到了问题。 I tried different solutions available on stack overflow and nothing work for me.
我在堆栈溢出时尝试了不同的解决方案,但对我来说没有任何效果。
This solution works for me.
这个解决方案对我有用。
brew uninstall --force node
brew uninstall --force node
brew install node
brew install node
再次安装它First point remove all node versions if available.如果可用,第一点删除所有节点版本。
Done.完成。 Enjoy coding.
享受编码。
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." “如果你是 Homebrew 用户并且你通过 Homebrew 安装了 node,那么 Homebrew 和 NPM 的协同工作方式存在一个重大的哲学问题。”
Kudos to Dan Herbert for the solution.感谢 Dan Herbert 提供的解决方案。
Remove all file from following folder从以下文件夹中删除所有文件
A)C:\\Users\\\\AppData\\Roaming\\npm A)C:\\Users\\\\AppData\\Roaming\\npm
B)C:\\Users\\\\AppData\\Roaming\\npm-cache B)C:\\Users\\\\AppData\\Roaming\\npm-cache
and install node
again并再次
install node
then execute command " npm install -g @angular/cli
"然后执行命令“
npm install -g @angular/cli
”
None of the other answered solved my issue.其他人的回答都没有解决我的问题。 After reinstalling Node, I still got the same error (even when I just wrote
npm -v
).重新安装 Node 后,我仍然遇到同样的错误(即使我刚刚写了
npm -v
)。
I followed this answer here (removing everything called node and npm), which solved it for me.我在这里遵循了这个答案(删除了所有名为 node 和 npm 的内容),它为我解决了这个问题。
In my case, the solution to the problem was reinstalling the node using the official installer from https://nodejs.org (Mac OS).就我而言,问题的解决方案是使用https://nodejs.org (Mac OS) 的官方安装程序重新安装节点。
Solution:解决方法:
PS The problem appeared after yarn installation. PS纱线安装后出现问题。
One other suggestion after trying these that finally worked for me was simply upgrading my node by downloading the latest via the download and package installer from here:尝试这些最终对我有用的另一个建议是通过从这里下载最新的下载和包安装程序来升级我的节点:
https://nodejs.org/en/download/ https://nodejs.org/en/download/
Before doing this trying to run any npm command gave me the same error brought in OP's question在这样做之前,尝试运行任何 npm 命令都给我带来了 OP 问题中的相同错误
npm commands started working for me after that.在那之后,npm 命令开始为我工作。
对不起,但在我的情况下,我遇到了同样的错误,因为我的 index.js 在 de src 文件夹中,请确保您在 index.js 的 seme 目录中运行
In my case, this happened after I performed a machine-wide clean-up of all node_modules folders.就我而言,这是在我对所有 node_modules 文件夹执行机器范围内的清理之后发生的。 I had node installed with nvm and I started getting this error, no matter what node-related action I wanted to trigger:
我用nvm安装了节点,但我开始收到此错误,无论我想触发什么与节点相关的操作:
Error: Cannot find module '../lib/utils/unsupported.js'
I solved it by doing the following:我通过执行以下操作解决了它:
I had the same error after brew upgrade
on mac.在 mac 上
brew upgrade
后我遇到了同样的错误。 I did brew postinstall node
and that fixed it.我做了
brew postinstall node
并修复了它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.