当我运行“Ionic start project name”时,我总是得到这个错误消息:

错误消息

Running command - failed![ERROR] An error occurred while running npm install (exit code 1):

    module.js:471
        throw err;
        ^

    Error: Cannot find module '../lib/utils/unsupported.js'
        at Function.Module._resolveFilename (module.js:469:15)
        at Function.Module._load (module.js:417:25)
        at Module.require (module.js:497:17)
        at require (internal/module.js:20:19)
        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:79:3)
        at Module._compile (module.js:570:32)
        at Object.Module._extensions..js (module.js:579:10)
        at Module.load (module.js:487:32)
        at tryModuleLoad (module.js:446:12)

当前回答

我通过删除node_modules,然后重新安装节点稳定版本来解决这个问题。

其他回答

https://nodejs.org/en/

只需从官网下载节点,这对我有用!:)

这是一个关于从你的计算机操作系统中移除节点的有用视频和博客文章。这是一种不同的删除方法,基于您最初安装节点的方式(brew vs.从https://nodejs.org/en/下载的二进制文件)

if you installed node with Homebrew then brew uninstall node will work. Verify that with running a node -v command in your terminal. Otherwise and if you have installed the binary file from nodeJS's websitethen you have to run this command in your terminal: sudo rm -rf /usr/local/{bin/{node,npm},lib/node_modules/npm,lib/node,share/man/*/node.*}. Again, verify that with running a node -v command. In both cases, successful removal of node should result in bash not recognizing what node is if it is completely removed

如果你正在使用“n”库@ https://github.com/tj/n。执行以下步骤

  echo $NODE_PATH

如果节点路径为空,则

sudo n latest    - sudo is optional depending on your system

使用n切换Node.js版本后,npm可能无法正常工作。

curl -0 -L https://npmjs.com/install.sh | sudo sh
echo NODE_PATH

您现在应该看到您的节点路径。否则,它可能是别的东西

我也遇到过类似的问题。当我尝试通过npm test执行Mocha时,无法找到/lib/utils目录。我尝试了这里提到的解决方案,但没有成功。最终,我卸载并重新安装了Mocha包,它是我工作的npm项目中的一个依赖项,在那之后它就工作了。因此,如果有人在将npm包作为依赖项安装时遇到了这个问题,请尝试卸载并重新安装该包(如果您还没有安装过)!

你可以运行这个命令,它会自动删除以前的npm版本,并安装新版本,详情https://github.com/npm/cli

curl -qL https://www.npmjs.com/install.sh | sh