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

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

在MacOS上使用Homebrew:

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

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

首先确保你有最新的版本

brew update

删除之前的node实例:

brew uninstall node

然后重新安装最新版本:

brew install node

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

brew link --overwrite node 

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

在我的情况下,它是$NODE_PATH丢失:

NODE="/home/ubuntu/local/node" #here your user account after home
NODE_PATH="/usr/local/lib/node_modules" 
PATH="$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:$NODE/bin:$NODE/lib/node_modules"

只回显$NODE_PATH空表示未设置。建议将它们添加到.bashrc中。

如果你正在使用“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

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

在Mac OS X(10.12.6)上,我通过以下方法解决了这个问题:

brew uninstall --force node
brew install node

然后我得到一个错误,抱怨节点postinstall失败,并重新运行brew postinstall节点

然后我得到一个错误:

permission denied @ rb_sysopen /usr/local/lib/node_modules/npm/bin/npx

我通过以下方法解决了这个错误:

sudo chown -R $(whoami):admin /usr/local/lib/node_modules

现在我不会再得到这个错误了。

如前所述。

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

在fedora 27上,我这样解决了这个问题:

sudo rm -f  /usr/local/lib/node_modules/npm
sudo dnf reinstall nodejs

这是一个关于从你的计算机操作系统中移除节点的有用视频和博客文章。这是一种不同的删除方法,基于您最初安装节点的方式(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

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

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

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

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

我按照前面的答案重新安装了节点。但是我得到了这个错误。

警告:安装后步骤未成功完成 重试使用brew postinstall节点

所以我执行了这个命令

sudo chown -R $(whoami):admin /usr/local/lib/node_modules/

然后跑了

brew postinstall node

我通过混合安装/更新方法得到了这个错误:通过从网站下载包安装节点,后来我使用brew更新。

我通过卸载brew版本来修复:

酿造卸载——忽略依赖项节点

然后我回到节点网站,通过包管理器下载并安装:https://nodejs.org/en/download/ 出于某种原因,再多的尝试通过brew重新安装都不起作用。

只需遵循三个步骤;

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

https://nodejs.org/en/

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

尝试了以上所有/旧的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。

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

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

在Windows上:

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

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

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

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

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

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