request to https://registry.npmjs.org/webpack failed, reason: unable to verify the first certificate

博客提到使用npm安装webpack时,出现无法验证第一个证书的错误,显示request to https://registry.npmjs.org/webpack failed, reason: unable to verify the first certificate,还称在命令窗口输入相关内容可解决。

通过npm安装webpack的时候,出现错误信息

request to https://registry.npmjs.org/webpack failed, reason: unable to verify the first certificate

 

在命令窗口中输入,即可

npm config set strict-ssl false

 

gapinyc@DESKTOP-9QS7RL5:~/superset-prod/superset-5.0.0/superset-frontend$ npm install npm warn deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful. npm warn deprecated lodash.isequal@3.0.4: This package is deprecated. Use require('node:util').isDeepStrictEqual instead. npm warn deprecated viewport-mercator-project@7.0.4: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. npm warn deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated npm warn deprecated lodash.get@4.4.2: This package is deprecated. Use the optional chaining (?.) operator instead. npm warn deprecated @babel/plugin-proposal-class-properties@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead. npm warn deprecated @babel/plugin-proposal-nullish-coalescing-operator@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead. npm warn deprecated @babel/plugin-proposal-private-methods@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-private-methods instead. npm warn deprecated request-promise-native@1.0.9: request-promise-native has been deprecated because it extends the now deprecated request package, see https://github.com/request/request/issues/3142 npm warn deprecated rimraf@2.6.3: Rimraf versions prior to v4 are no longer supported npm warn deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated npm warn deprecated har-validator@5.1.5: this library is no longer supported npm warn deprecated @humanwhocodes/config-array@0.13.0: Use @eslint/config-array instead npm warn deprecated lodash.isequal@4.5.0: This package is deprecated. Use require('node:util').isDeepStrictEqual instead. npm warn deprecated abab@2.0.6: Use your platform's native atob() and btoa() methods instead npm warn deprecated @babel/plugin-proposal-optional-chaining@7.21.0: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead. npm warn deprecated rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported npm warn deprecated rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported npm warn deprecated rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported npm warn deprecated rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported npm warn deprecated rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported npm warn deprecated domexception@1.0.1: Use your platform's native DOMException instead npm warn deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated npm warn deprecated @humanwhocodes/object-schema@2.0.3: Use @eslint/object-schema instead npm warn deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported npm warn deprecated glob@8.1.0: Glob versions prior to v9 are no longer supported npm warn deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated npm warn deprecated left-pad@1.3.0: use String.prototype.padStart() npm warn deprecated w3c-hr-time@1.0.2: Use your platform's native performance.now() and performance.timeOrigin. npm warn deprecated domexception@4.0.0: Use your platform's native DOMException instead npm warn deprecated sane@4.1.0: some dependency vulnerabilities fixed, support for node < 10 dropped, and newer ECMAScript syntax/features added npm warn deprecated nomnom@1.8.1: Package no longer supported. Contact support@npmjs.com for more info. npm warn deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details. npm warn deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142 npm warn deprecated @babel/polyfill@7.12.1: 🚨 This package has been deprecated in favor of separate inclusion of a polyfill and regenerator-runtime (when needed). See the @babel/polyfill docs (https://babeljs.io/docs/en/babel-polyfill) for more information. npm warn deprecated node-domexception@1.0.0: Use your platform's native DOMException instead npm warn deprecated topojson@1.6.27: Use topojson-client, topojson-server or topojson-simplify directly. npm warn deprecated eslint@8.57.1: This version is no longer supported. Please see https://eslint.org/version-support for other options. ⠇ 卡在这里了
10-24
### 问题分析 当执行 `npm install` 时出现错误 `unable to verify the first certificate`,这通常与网络环境或 SSL 证书验证有关。具体错误信息表明 npm 无法通过 HTTPS 协议访问官方镜像仓库 `https://registry.npmjs.org/`,并提示证书验证失败。此类问题常见于使用代理、公司内网、或镜像源配置不当的环境中。 ### 解决方案 #### 1. 检查并清除代理配置 如果系统中配置了代理(proxy),可能导致 HTTPS 请求失败。可通过以下命令检查当前代理设置: ```bash npm config get proxy npm config get https-proxy ``` 如果返回值不为 `null`,则清除代理配置: ```bash npm config set proxy null npm config set https-proxy null ``` #### 2. 更换 npm 镜像源 默认的 `https://registry.npmjs.org/` 在某些网络环境下访问不稳定,可临时切换为国内镜像源,如淘宝镜像: ```bash npm config set registry https://registry.npm.taobao.org/ ``` 安装完成后,可恢复默认源: ```bash npm config set registry https://registry.npmjs.org/ ``` #### 3. 更新 npm 和 Node.js 版本 旧版本的 npm(如 v6.x)或 Node.js(如 v12.x)可能存在兼容性问题。建议升级至较新版本: ```bash npm install -g npm@latest ``` 并确保 Node.js 版本不低于 v14.x。 #### 4. 检查系统时间和 SSL 证书 系统时间不准确可能导致证书验证失败。请确保操作系统时间与网络时间同步。此外,某些杀毒软件或防火墙可能干扰 HTTPS 连接,建议临时关闭相关软件测试是否问题消失。 #### 5. 使用 `--no-ssl-verify` 参数(谨慎使用) 如果上述方法无效,可尝试跳过 SSL 验证(不推荐长期使用): ```bash npm config set strict-ssl false ``` 此操作会降低安全性,仅适用于临时调试。 ### 示例命令组合 结合上述方法,可一次性执行以下命令: ```bash npm config set proxy null npm config set https-proxy null npm config set registry https://registry.npm.taobao.org/ npm install cross-env ``` 安装完成后,若需恢复默认源: ```bash npm config set registry https://registry.npmjs.org/ ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值