使用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-providerNODE_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
相关产品推荐
相关产品推荐

