问题

偶尔一次在windows安装nvm后,安装指定版本的nodejs,结果nodejs安装成功,而npm安装失败,连续重试了几次,都安装失败,只能通过离线安装的方式安装npm这个模块了。

错误内容如下:

Downloading node.js version 12.22.12 (64-bit)...
Complete
Downloading npm version 6.14.16... Error while downloading https://github.com/npm/cli/archive/v6.14.16.zip - Get "https://github.com/npm/cli/archive/v6.14.16.zip": dial tcp 140.82.114.4:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
Could not download npm for node v12.22.12.
Please visit https://github.com/npm/cli/releases/tag/v6.14.16 to download npm.
It should be extracted to H:\Dev\nvm\v12.22.12

解决方案

在线重试安装

1、先卸载对应版本,比如:12.22.12

nvm uninstall 12.22.12

2、再安装对应版本

nvm install 12.22.12

3、使用对应版本

nvm use 12.22.12

离线安装

1、先卸载对应版本,比如:12.22.12

nvm uninstall 12.22.12

2、再安装对应版本

nvm install 12.22.12

3、下载nodejs包 这个时候,如果还不可以,则需要前往 https://nodejs.org/download/release/ 这里想在相应版本的zip包,解压nvm中对应版本的nodejs中。 目录结构如下:

node_modules
node.exe
npm
npm.cmd
npx
npx.cmd