npm 安装 cnpm 抛出 unable to verify the first certificate 错误

npm
本文将介绍怎样解决在使用 npm 安装 cnpm 时抛出 unable to verify the first certificate 错误。

在使用 npm 安装 cnpm 时抛出了“unable to verify the first certificate”错误信息,详细信息如下图:

npm 安装 cnpm 抛出 unable to verify the first certificate 错误

从上面错误消息可知,这是由于 HTTPS 证书验证失败。我们可以使用“npm config list”查看 npm 的配置信息,如下:

C:\Users\Administrator>npm config list
; cli configs
metrics-registry = "http://registry.npm.taobao.org/"
scope = ""
user-agent = "npm/6.14.8 node/v14.14.0 win32 x64"

; userconfig C:\Users\Administrator\.npmrc
registry = "http://registry.npm.taobao.org/"
strict-ssl = true

; builtin config undefined
prefix = "C:\\Users\\Administrator\\AppData\\Roaming\\npm"

; node bin location = D:\programFiles2\nodejs\node.exe
; cwd = C:\Users\Administrator
; HOME = C:\Users\Administrator
; "npm config ls -l" to show all defaults.

上面配置中,strict-ssl 为 true,表示开启了 HTTPS 认证。为了解决上面的错误,需要执行“npm config set strict-ssl false”命令。执行成功后,查看“C:\Users\Administrator\.npmrc”文件。文件内容如下:

registry=http://registry.npm.taobao.org/
strict-ssl=false

当然你也可以使用“npm config list”命令查看。

再次执行“npm install -g cnpm --registry=https://registry.npm.taobao.org  ”命令安装 cnpm,如下图:

npm 安装 cnpm 抛出 unable to verify the first certificate 错误

npm config用法

下面是 npm config 的所有用法,如下:

  • npm config set <key> <value>:设置指定配置的值,如:npm config set strict-ssl false

  • npm config get [<key>]:获取指定 key 的配置信息,如:npm config get strict-ssl

  • npm config delete <key>:删除指定 key 配置信息,如:npm config delete strict-ssl

  • npm config list [--json]:获取所有的配置信息

  • npm config edit:运行改命令将使用系统默认编辑器打开配置文件,然后进行编辑即可。在 windows 下将由记事本打开。

  • npm set <key> <value>:和上面的命令“npm config set <key> <value>”类似

  • npm get [<key>]:和上面的命令“npm config get [<key>]”类似

更多关于 npm 命令的用法可以参考:https://www.npmjs.cn/cli/npm/

成熟不是人的心变老,而是泪在眼眶里打转还能微笑。
0 不喜欢
说说我的看法 -
全部评论(
没有评论
关于
本网站属于个人的非赢利性网站,转载的文章遵循原作者的版权声明,如果原文没有版权声明,请来信告知:hxstrive@outlook.com
公众号