【问题标题】:npm error UNABLE_TO_GET_ISSUER_CERT_LOCALLY, how to generate a .pem file from a bundle of certificates and that bundle as well?npm 错误 UNABLE_TO_GET_ISSUER_CERT_LOCALLY,如何从证书包和该包生成 .pem 文件?
【发布时间】:2017-06-08 06:49:07
【问题描述】:

使用 Webstorm 和 Node.js,我正在尝试通过 npm 安装 ursa 模块。我需要这个模块,因为它是另一个模块的先决条件。

当我安装时,node-gyp rebuild 上的安装失败。

控制台输出如下:

C:\Users\{Me}>npm install ursa --save
> ursa@0.9.4 install C:\Users\{Me}\node_modules\ursa
> node-gyp rebuild

C:\Users\Me\node_modules\ursa>if not defined npm_config_node_gyp 
(node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..
\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "" rebuild )
gyp WARN install got an error, rolling back install
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 6.1.7601
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" 
"C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\{Me}\node_modules\ursa
gyp ERR! node -v v6.11.0
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.1: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "ursa" "--save"
npm ERR! node v6.11.0
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE

npm ERR! ursa@0.9.4 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ursa@0.9.4 install script 'node-gyp rebuild'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the ursa package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs ursa
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls ursa
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! C:\Users\p704644d\{Me}\npm-debug.log

如果需要,我可以提供日志文件。

我google了一下,发现:

npm 错误!代码 UNABLE_TO_GET_ISSUER_CERT_LOCALLY

此错误表示链中存在 TLS 证书 由未知的证书颁发机构 (CA) 签名。想必, 这是一个人的 HTTPS 代理使用的证书。 解决方法是配置cafile值:

$ npm config set cafile /path/to/your/file.pem

如果需要,您可以从 .crt 文件生成 .pem 文件:

来源:https://github.com/npm/npm/wiki/Troubleshooting

$ openssl x509 -inform der -in /path/to/the.crt -out /path/to/the/file.pem

问题是,我如何知道安装失败的证书,以及如何生成 .pem 文件?我应该在哪里找到我的证书以及如何捆绑它们以获得一个 .pem 文件? (在 Win 7 上)

【问题讨论】:

    标签: npm ca


    【解决方案1】:

    如果您位于将 SSL 证书与 SSL 检查交换的公司防火墙后面,请向您的网络管理员索取证书文件。否则,您可以通过连接到交换证书的任何网站,使用 Firefox 或 Chrome 下载它。然后您可以使用NODE_EXTRA_CA_CERTS 将证书文件提供给Node.js,正如我在How to add custom certificate authority (CA) to nodejs 中所回答的那样。

    【讨论】:

      猜你喜欢
      • 2018-02-03
      • 2017-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-23
      • 2022-08-16
      • 2017-07-30
      • 1970-01-01
      相关资源
      最近更新 更多