当我运行“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)

当前回答

尝试了以上所有/旧的brew安装答案,没有一个是为我的笔记本电脑工作。

只有下面的方法可以解决我的问题。

1)执行如下命令:

sudo rm -rf /usr/local/lib/node_modules/npm
brew uninstall --force node      

2)进入Node.js官方网站https://nodejs.org/en/download/current/下载最新安装包。

3)再次运行你的npm命令,它应该不再有任何错误。

此方法适用于macOS Mojave Version 10.14.4。

其他回答

是的,你应该重新安装节点:

sudo rm -rf /usr/local/lib/node_modules/npm
 brew uninstall --force node                
 brew install node

这可能发生在npm/lib文件夹由于某种原因被清空时(也可能发生在上次使用时由于权限问题)。

重新安装节点可以解决这个问题(正如这里的其他答案所述),但我建议使用一个叫做nvm(节点版本管理器)的很棒的工具,它能够管理多个版本的node和npm -这在开发机器上非常有用,因为有多个项目需要不同版本的node。

当你安装nvm时,这个消息就会消失,你就可以使用最新版本的node和npm了。

为了查看nvm中当前安装的节点版本列表,只需运行:

nvm list

要安装和使用新的节点版本,请运行:

nvm install <node_version>

例如安装节点10的最新版本。x,运行:

nvm install 10

为了切换到当前安装的版本,运行:

nvm use <node_version>

为了切换到系统的原始节点版本,只需运行:

nvm use system

希望这能有所帮助。

好运!

./lib/node_modules/npm/bin/npm-cli.js中的require('../lib/utils/unsupported.js')导致无法找到模块'../lib/utils/unsupported.js'错误。

根据nodejs require docs,所需的模块相对于文件进行搜索,因为它以../开头。

因此,如果我们从。/lib/node_modules/npm/bin/npm-cli.js开始选择相对路径../lib/utils/unsupported.js,那么所需的模块必须位于。/lib/node_modules/npm/lib/utils/unsupported.js中。如果它不在那里,我看到两个选项:

the installation is corrupt, in which case Vincent Ducastel's answer to reinstall node might work npm is no symlink to ./lib/node_modules/npm/bin/npm-cli.js. This is what caused the error in my setup. If you call npm, it will typically find it be searching it in the directories listed in the PATH env var. It might for example be located in ./bin. However, npm in a ./bin directory should only be a symlink to the aforementioned ./lib/node_modules/npm/bin/npm-cli.js. If it is not a symlink but directly contains the code, somewhere in the installation process the symlink got replaced by the file it links to. In this case, it should be sufficient to recreate the symlink: cd ./bin; rm npm; ln -s ../lib/node_modules/npm/bin/npm-cli.js npm (update: command fixed, thx @massimo)

所有建议检查NODE_PATH或npmrc配置的答案都应该被忽略,因为相对地搜索模块时不会考虑这些。

在Windows上:

移除~/AppData/Roaming目录下的npm文件夹

在我的macOS(10.13.3)中,我在重新安装Node版本管理器后解决了这个问题。

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
source ~/.bashrc