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

问题描述:

我刚刚在 Rails 环境中工作后回来做 React 项目,发现我无法在我的 Mac 终端中运行任何 NPM 命令.我已经尝试了我遇到的所有补救措施,但都没有奏效.更大的问题是导致这种情况的原因以及如何避免再次发生.

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.

这是错误.我需要做什么?请帮忙.

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)

我尝试了以下方法:

$brew update
$brew uninstall node
$brew install node

之后出现以下命令,当 $which npm 之前是未知命令时:

After which the following commands come up as so when $which npm was unknown command before:

$which npm
/usr/local/bin/npm

$which node
/usr/local/bin/node

我什至尝试过跑步:

/usr/local/bin/npm -v

但是得到和上面一样的错误

but get the same error as above while

/usr/local/bin/node -v
v9.11.1

工作正常.

将以下内容添加到我的 .zshrc 文件中:

added the following to my .zshrc file:

export PATH=/usr/local/bin/node:$PATH
export PATH=/usr/local/bin/npm:$PATH

我也试过:

$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    

那么,

$node install

但这也行不通.

$echo $NODE_PATH

确实是空的,所以我可能需要在我的 .bashrc 中添加以下内容.

does come up empty, so I may need to added the following to my .bashrc.

export PATH="/usr/local/bin/npm:/usr/local/bin/node:/usr/local/bin:$PATH" 

那也不行.

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