记录一下npm安装时的错误排查过程

1.npm安装时遇到error,从error1 处查看最初的报错内容比较准


2.根据error的内容查看是哪个依赖项引起的错,查阅package.json里对应的依赖版本和当前的node.js版本是否一致

3.缺少C++、python等环境,按照缺失项,安装对应的运行环境

npm ERR! gyp verb check python checking for Python executable "python2" in the PATH
npm ERR! gyp verb `which` failed Error: not found: python2

4.缺少微软C++相关的开发库

gyp ERR! build error gyp ERR! stack Error: `C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe` failed with exit code: 1

关键字是Visual Studio,需要下载相关依赖

5.某些依赖链接已经失效404,或者提示建立连接失败和代理

如下面这个会提示链接超时,并且手动打开对应的链接也是404页面

> node-sass@3.13.1 install D:\workspace\node_modules\node-sass
> node scripts/install.js

Downloading binary from https://github.com/sass/node-sass/releases/download/v3.13.1/win32-x64-64_binding.node
Cannot download "https://github.com/sass/node-sass/releases/download/v3.13.1/win32-x64-64_binding.node":

connect ETIMEDOUT 20.205.243.166:443

Timed out whilst downloading the prebuilt binary

Hint: If github.com is not accessible in your location
      try setting a proxy via HTTP_PROXY, e.g.

      export HTTP_PROXY=http://example.com:1234

or configure npm proxy via

      npm config set proxy http://example.com:8080

可以设置镜像(淘宝的镜像不一定好使)、单独安装失败的依赖设置(链接必须得能访问才行,老链接失效得多)

如果更换了地址还是下载不了,直接用命令安装对应的缺失版本:

这里是在github上找到了对应原来缺失的sass 3.4.2版本库文件

npm install git+https://github.com/sass/node-sass.git#v3.4.2 --save

6.某些依赖项可能是从github上以ssh拉取的,如果本地不配置github的ssh密钥会一直timeout,配置完以后git可以拉取说明配置成功

checking installable status 就卡主,然后就timeout,看到了报错内容里有关键字git和ssh

npm WARN deprecated domexception@1.0.1: Use your platform's native DOMException instead [ ...............] \ fetchMetadata: sill resolveWithNewModule camelcase@4.1.0

 手动测试

D:\workspace\git-test>ssh -T git@github.com
ssh: connect to host github.com port 22: Connection timed out

D:\workspace\git-test>git clone ssh://git@github.com/sohee-lee7/Squire.git
Cloning into 'Squire'...
ssh: connect to host github.com port 22: Connection timed out
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

D:\workspace\git-test>git clone ssh://git@github.com/sohee-lee7/Squire.git
Cloning into 'Squire'...
remote: Enumerating objects: 3598, done.
remote: Total 3598 (delta 0), reused 0 (delta 0), pack-reused 3598
Receiving objects: 100% (3598/3598), 3.08 MiB | 1.59 MiB/s, done.

生成github密钥,会在当前~/ssh生成图中文件,还需要手动创建配置,让git的ssh生效才行

7.某些依赖可能是从github上以http协议拉取的,国内很多情况无法通过http或https访问github,本地有vpn的话得手动给git配置上代理

npm报错中出现了git.EXE ls-remote -h -t https://github.com/nhn/raphael.git这行,手动测试发现拉不下来就还是git网络问题

8.某些依赖可能是npm直接拉去二进制流形式下载的,同理,npm也需要配置代理 ,但是本人测试以后发现npm配置代理会卡主,但是可以对cmd窗口配置临时的代理(窗口关闭失效),也对npm生效

npm代理,不行

临时cmd窗口代理,行

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值