当前位置: 代码网 > it编程>前端脚本>Node.js > npm安装时的错误排查的方法

npm安装时的错误排查的方法

2024年09月12日 Node.js 我要评论
1.npm安装时遇到error,从error1 处查看最初的报错内容比较准2.根据error的内容查看是哪个依赖项引起的错,查阅package.json里对应的依赖版本和当前的node.js版本是否一

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窗口代理,行

到此这篇关于npm安装时的错误排查的方法的文章就介绍到这了,更多相关npm安装错误排查内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com