Javascript $npm 安装后,出现错误:找不到模块 '../lib/utils/unsupported.js'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49684857/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 04:26:57  来源:igfitidea点击:

After $npm install, Getting Error: Cannot find module '../lib/utils/unsupported.js'

javascriptnode.jsreactjsnpm

提问by bigmugcup

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.

那也行不通。

回答by Lucas Lopes

  1. Uninstall node brew uninstall --force node
  2. Remove the /usr/local/lib/node_modulesfolder
  3. Install it again brew install node
  1. 卸载节点 brew uninstall --force node
  2. 删除/usr/local/lib/node_modules文件夹
  3. 重新安装 brew install node

回答by Popeye

Assume this happens on MacOS, below solution works for me.

假设这发生在 MacOS 上,下面的解决方案对我有用。

  1. brew uninstall --force node
  2. Visit https://nodejs.org/en/and download the LTS version and install, the error was gone
  1. brew 卸载 --force 节点
  2. 访问https://nodejs.org/en/并下载 LTS 版本并安装,错误消失

回答by T. Dayya

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

回答by Rehan Ali

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.

这个解决方案对我有用。

  1. Uninstall node all version brew uninstall --force node
  2. Install it again by this brew install node
  1. 卸载节点所有版本 brew uninstall --force node
  2. 通过这个重新安装它 brew install node

First point remove all node versions if available.

如果可用,第一点删除所有节点版本。

Done. Enjoy coding.

完毕。享受编码。

回答by Manoj Gupta

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 nodeagain

install node再次

then execute command "npm install -g @angular/cli"

然后执行命令“ npm install -g @angular/cli

回答by Zeth

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 everythingcalled node and npm), which solved it for me.

在这里遵循了这个答案(删除了所有名为 node 和 npm 的内容),它为我解决了这个问题。

回答by bhoodream

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:

解决方案:

  1. Download node installer from https://nodejs.org
  2. Install it
  1. https://nodejs.org下载节点安装程序
  2. 安装它

P.S.The problem appeared after yarn installation.

PS纱线安装后出现问题。

回答by imazio

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 提供的解决方案。

回答by Paul Razvan Berg

In my case, this happened after I performed a machine-wide clean-up of all node_modules folders. I had node installed with nvmand I started getting this error, no matter what node-related action I wanted to trigger:

就我而言,这是在我对所有 node_modules 文件夹执行机器范围内的清理之后发生的。我用nvm安装了节点,我开始收到此错误,无论我想触发什么与节点相关的操作:

Error: Cannot find module '../lib/utils/unsupported.js'

I solved it by doing the following:

我通过执行以下操作解决了它:

  1. Restarted my computer
  2. Uninstalled nvm
  3. Installed a different node version
  1. 重新启动了我的电脑
  2. 卸载了 nvm
  3. 安装了不同的节点版本

回答by Travis Libby

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 命令开始为我工作。