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.jsDownloading 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 outD:\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窗口代理,行
到此这篇关于npm安装时的错误排查的方法的文章就介绍到这了,更多相关npm安装错误排查内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!