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

当前回答

我通过运行下面的命令解决了这个问题

NVM安装节点——reinstall-packages-from=node

其他回答

尝试删除/usr/local/lib/node_modules/npm并重新安装node。这应该有用。

在MacOS上使用Homebrew:

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

只需遵循三个步骤;

强制清除npm缓存: NPM缓存清理-f 使用npm全局安装n个包: NPM install -g 从以下三个选项中任意一个安装: A. sudo n stable(获取稳定版) B. sudo n latest(获取节点的最新版本) C. sudo n X.X.X(获取节点的具体版本)

./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配置的答案都应该被忽略,因为相对地搜索模块时不会考虑这些。

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

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

我收到了类似的错误,现在有它的工作。

首先确保你有最新的版本

brew update

删除之前的node实例:

brew uninstall node

然后重新安装最新版本:

brew install node

然后确保它被符号链接到/usr/local(如果还没有)。您将得到一个错误,让您知道要完成这一步。

brew link --overwrite node 

关于如何安装/升级节点的更多详细信息也可用。