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

使用npx create-react-app时遇ERR_SSL_CIPHER_OPERATION_FAILED错误求助

解决npx create-react-app时的ERR_SSL_CIPHER_OPERATION_FAILED错误

问题描述

执行npx create-react-app react-app创建React项目时,触发SSL加密操作失败错误,具体报错信息如下:

npm ERR! code ERR_SSL_CIPHER_OPERATION_FAILED
npm ERR! errno ERR_SSL_CIPHER_OPERATION_FAILED
npm ERR! Invalid response body while trying to fetch https://registry.npmjs.org/eslint: 48090000:error:1C800066:Provider routines:ossl_gcm_stream_update:cipher operation failed:c:\ws\deps\openssl\openssl\providers\implementations\ciphers\ciphercommon_gcm.c:320:
npm ERR!

npm ERR! A complete log of this run can be found in: C:\Users\KRISHNA\AppData\Local\npm-cache\_logs\2023-10-03T10_41_53_464Z-debug-0.log

Aborting installation.
npm install --no-audit --save --save-exact --loglevel error react react-dom react-scripts cra-template has failed.

已尝试的无效操作

  • 检查并确认网络连接稳定
  • 通过npm install -g npm@latest更新Node.js和npm到最新版本
  • 带--verbose参数执行npm install获取详细输出
  • 执行npm cache clean -f清除npm缓存
  • 通过npm config set registry http://registry.npmjs.org/将npm registry切换为HTTP而非HTTPS

解决方案

1. 禁用OpenSSL硬件加速

该错误与OpenSSL的GCM加密硬件加速兼容性有关,可通过设置环境变量禁用:

  • Windows系统:
    临时生效(当前命令行窗口):
    set NODE_OPTIONS=--openssl-legacy-provider
    
    永久生效:右键「此电脑」→ 属性 → 高级系统设置 → 环境变量 → 新建系统变量,变量名NODE_OPTIONS,变量值--openssl-legacy-provider
  • macOS/Linux系统:
    临时生效(当前终端窗口):
    export NODE_OPTIONS=--openssl-legacy-provider
    
    永久生效:将上述命令写入~/.bashrc或~/.zshrc配置文件

2. 切换到国内npm镜像源

国内镜像源可规避部分SSL连接问题,执行以下命令切换:

npm config set registry https://registry.npmmirror.com/

切换完成后重新执行npx create-react-app react-app

3. 更新系统SSL根证书

  • Windows系统:打开「设置」→「更新和安全」→「Windows更新」,检查并安装所有系统更新(包含根证书更新)
  • 手动导入证书:访问https://registry.npmjs.org,下载站点SSL证书,导入到系统信任的根证书颁发机构列表

4. 降级Node.js到LTS版本

部分新版本Node.js与OpenSSL存在兼容性问题,可尝试降级到稳定LTS版本(如18.x或16.x),使用nvm管理版本:

# 安装nvm后执行
nvm install 18.17.0
nvm use 18.17.0

切换版本后重新尝试创建项目

内容的提问来源于stack exchange,提问作者Bala Krishna S

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.09 07:25:11