You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular 14新建项目报ERR_SSL_DECRYPTION_FAILED错误如何解决

运行环境
  • Windows 10
  • nodejs 16.16.0
  • npm 8.14.0
  • angular 14.0.6
问题描述

执行以下命令新建Angular项目时:

ng new myproject

出现TLS错误,错误码如下:

npm ERR! code ERR_SSL_DECRYPTION_FAILED_OR_BAD_RECORD_MAC

已尝试执行以下操作排查修复:

npm set strict-ssl false
npm cache clear --force
cd myproject
npm i

但问题始终未解决。

错误日志片段
npm ERR! code ERR_SSL_DECRYPTION_FAILED_OR_BAD_RECORD_MAC
npm ERR! errno ERR_SSL_DECRYPTION_FAILED_OR_BAD_RECORD_MAC
    3740 verbose stack FetchError: Invalid response body while trying to fetch https://registry.npmjs.org/postcss-modules-local-by-default: 17396:error:1408F119:SSL routines:ssl3_get_record:decryption failed or bad record mac:c:\ws\deps\openssl\openssl\ssl\record\ssl3_record.c:677:
    3740 verbose stack
    3740 verbose stack     at C:\Users\techn\AppData\Roaming\npm\node_modules\npm\node_modules\minipass-fetch\lib\body.js:168:15
    3740 verbose stack     at processTicksAndRejections (node:internal/process/task_queues:96:5)
    3740 verbose stack     at async RegistryFetcher.packument (C:\Users\techn\AppData\Roaming\npm\node_modules\npm\node_modules\pacote\lib\registry.js:99:25)
    3740 verbose stack     at async RegistryFetcher.manifest (C:\Users\techn\AppData\Roaming\npm\node_modules\npm\node_modules\pacote\lib\registry.js:124:23)
    3740 verbose stack     at async Promise.all (index 203)
    3740 verbose stack     at async Arborist.[buildDepStep] (C:\Users\techn\AppData\Roaming\npm\node_modules\npm\node_modules\@npmcli/arborist\lib\arborist\build-ideal-tree.js:1093:5)
    3740 verbose stack     at async Arborist.buildIdealTree (C:\Users\techn\AppData\Roaming\npm\node_modules\npm\node_modules\@npmcli/arborist\lib\arborist\build-ideal-tree.js:218:7)
    3740 verbose stack     at async Promise.all (index 1)
    3740 verbose stack     at async Arborist.reify (C:\Users\techn\AppData\Roaming\npm\node_modules\npm\node_modules\@npmcli/arborist\lib\arborist\reify.js:154:5)
    3740 verbose stack     at async Install.exec (C:\Users\techn\AppData\Roaming\npm\node_modules\npm\lib\commands\install.js:145:5)
补充说明

通过浏览器可正常访问地址https://registry.npmjs.org/postcss-modules-local-by-default。

故障处理方案

按以下优先级依次操作排查:

  • 第一步:切换npm源为国内镜像,执行命令:
npm config set registry https://registry.npmmirror.com

执行完成后重新运行ng new myproject。
注:浏览器可正常访问官方源不代表命令行请求链路正常,运营商链路劫持、代理规则不匹配都会导致命令行SSL握手失败,国内镜像可直接规避这类公网链路问题。

  • 第二步:若切换源后仍报错,检查代理配置:
    先关闭系统全局代理、第三方网络加速工具后重试;如果必须使用代理,单独为npm配置HTTP形式的本地代理,执行命令(替换为你本地实际的代理端口):
npm config set proxy http://127.0.0.1:端口号
npm config set https-proxy http://127.0.0.1:端口号

npm 8.x版本对Socks协议代理兼容性差,配置Socks代理会固定触发本次的SSL解密错误,不要使用Socks协议配置npm代理。

  • 第三步:以上操作无效时,将Node.js降级至16.15.0版本:
    Node.js 16.16.0内置的OpenSSL版本存在已知的SSL记录校验缺陷,在部分Windows网络环境下会稳定触发本次报错,卸载当前版本Node.js,安装16.15.0 LTS版本后,重新全局安装@angular/cli即可恢复正常。

内容的提问来源于stack exchange,提问作者Emmanuel BRUNET

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.26 19:06:43