gyp ERR,Npm 无法获取本地发行人证书

met*_*man 12 npm node-gyp npm-install angular

我正在处理干净的 Windows 10 安装。唯一的事情是我安装了 cygwin 以在 cmd 中获取 unix 命令。

当我输入时,npm install -g @angular/cli它会下载必要的文件,但我收到一个错误:

gyp ERR! configure error
gyp ERR! stack Error: unable to get local issuer certificate
gyp ERR! stack     at Error (native)
gyp ERR! stack     at TLSSocket.<anonymous> (_tls_wrap.js:1092:38)
gyp ERR! stack     at emitNone (events.js:86:13)
gyp ERR! stack     at TLSSocket.emit (events.js:185:7)
gyp ERR! stack     at TLSSocket._finishInit (_tls_wrap.js:610:8)
gyp ERR! stack     at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:440:38)
gyp ERR! System Windows_NT 10.0.15063
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\user\\AppData\\Roaming\\npm\\node_modules\\@angular\\cli\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd C:\Users\user\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\node-sass
gyp ERR! node -v v6.11.2
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
Build failed with error code: 1
Run Code Online (Sandbox Code Playgroud)

我编辑了 npm 配置文件,如“npm config edit”。在打开的文件中,我添加了以下设置:

strict-ssl=false
http_proxy=null
proxy=null
Run Code Online (Sandbox Code Playgroud)

但这不起作用,我仍然收到相同的错误。更重要的是,npm install也会以相同的结果中断。

Emo*_*mon 28

我遇到过同样的问题。下面解决了我的问题

set NODE_TLS_REJECT_UNAUTHORIZED=0 然后npm install

可以参考:https : //github.com/nodejs/node-gyp/issues/695

  • 作为开发的临时修复是很好的,但在部署时应该避免这种情况,因为它会让您遭受中间人攻击。更好的方法是在虚拟机或容器中正确设置 SSL。 (2认同)
  • 这将关闭证书颁发机构为防止中间人攻击而提供的安全性。 (2认同)
  • 这对我来说不起作用,尽管我可以看到警告中提到的命令使 HTTPS 请求不安全。npm 的类似设置有效,但 gyp 仍然给出同样的垃圾 (2认同)

rak*_*aht 5

@Emon 的答案是正确的,但是对于 Linuz 用户来说,命令显然是:

export NODE_TLS_REJECT_UNAUTHORIZED=0
Run Code Online (Sandbox Code Playgroud)

  • 这将关闭证书颁发机构为防止中间人攻击而提供的安全性。 (2认同)