执行yarn start -ssl时遇digital envelope routines::unsupported错误求助
解决Node.js 18下
yarn start -ssl报ERR_OSSL_EVP_UNSUPPORTED错误 问题重现
执行yarn start -ssl时触发以下错误,已尝试重新执行yarn install但问题未解决:
Generating browser application bundles (phase: building)...Error: error:0308010C:digital envelope routines::unsupported at new Hash (node:internal/crypto/hash:71:19) at Object.createHash (node:crypto:133:10) at BulkUpdateDecorator.hashFactory (/Users/abhijith/Downloads/2205/js-storefront/teststore/node_modules/webpack/lib/util/createHash.js:145:18) at BulkUpdateDecorator.update (/Users/abhijith/Downloads/2205/js-storefront/teststore/node_modules/webpack/lib/util/createHash.js:46:50) at OriginalSource.updateHash (/Users/abhijith/Downloads/2205/js-storefront/teststore/node_modules/webpack/node_modules/webpack-sources/lib/OriginalSource.js:104:8) at NormalModule._initBuildHash (/Users/abhijith/Downloads/2205/js-storefront/teststore/node_modules/webpack/lib/NormalModule.js:868:17) at handleParseResult (/Users/abhijith/Downloads/2205/js-storefront/teststore/node_modules/webpack/lib/NormalModule.js:934:10) at /Users/abhijith/Downloads/2205/js-storefront/teststore/node_modules/webpack/lib/NormalModule.js:1026:4 at processResult (/Users/abhijith/Downloads/2205/js-storefront/teststore/node_modules/webpack/lib/NormalModule.js:743:11) at /Users/abhijith/Downloads/2205/js-storefront/teststore/node_modules/webpack/lib/NormalModule.js:807:5 ⠦ Generating browser application bundles (phase: building)...node:internal/crypto/hash:71 this[kHandle] = new _Hash(algorithm, xofLen); ^ Error: error:0308010C:digital envelope routines::unsupported at new Hash (node:internal/crypto/hash:71:19) at Object.createHash (node:crypto:133:10) at BulkUpdateDecorator.hashFactory (/Users/abhijith/Downloads/2205/js-storefront/teststore/node_modules/webpack/lib/util/createHash.js:145:18) at BulkUpdateDecorator.update (/Users/abhijith/Downloads/2205/js-storefront/teststore/node_modules/webpack/lib/util/createHash.js:46:50) at OriginalSource.updateHash (/Users/abhijith/Downloads/2205/js-storefront/teststore/node_modules/webpack/node_modules/webpack-sources/lib/OriginalSource.js:104:8) at NormalModule._initBuildHash (/Users/abhijith/Downloads/2205/js-storefront/teststore/node_modules/webpack/lib/NormalModule.js:868:17) at handleParseResult (/Users/abhijith/Downloads/2205/js-storefront/teststore/node_modules/webpack/lib/NormalModule.js:934:10) at /Users/abhijith/Downloads/2205/js-storefront/teststore/node_modules/webpack/lib/NormalModule.js:1026:4 at processResult (/Users/abhijith/Downloads/2205/js-storefront/teststore/node_modules/webpack/lib/NormalModule.js:743:11) at /Users/abhijith/Downloads/2205/js-storefront/teststore/node_modules/webpack/lib/NormalModule.js:807:5 { opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ], library: 'digital envelope routines', reason: 'unsupported', code: 'ERR_OSSL_EVP_UNSUPPORTED' } Node.js v18.16.0 error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
问题原因
Node.js 17及以上版本默认启用OpenSSL 3.0,而旧版Webpack(或其依赖)使用的MD4等哈希算法在OpenSSL 3.0中被标记为不安全算法,导致兼容性冲突。
解决方案
临时兼容方案:执行启动命令时添加环境变量,强制使用旧版算法兼容模式
- Mac/Linux终端:
NODE_OPTIONS=--openssl-legacy-provider yarn start -ssl - Windows命令提示符:
set NODE_OPTIONS=--openssl-legacy-provider && yarn start -ssl - Windows PowerShell:
$env:NODE_OPTIONS="--openssl-legacy-provider"; yarn start -ssl
- Mac/Linux终端:
永久配置方案:修改项目
package.json的启动脚本,自动注入环境变量
找到scripts中的start命令,修改为:{ "scripts": { "start": "NODE_OPTIONS=--openssl-legacy-provider yarn start -ssl" // 若项目使用react-scripts等工具,替换为对应启动命令,例如: // "start": "NODE_OPTIONS=--openssl-legacy-provider react-scripts start -ssl" } }修改后直接执行
yarn start即可。升级依赖方案:升级Webpack到5.60.0及以上版本,该版本已适配OpenSSL 3.0
yarn upgrade webpack@latest同时同步升级相关依赖(如
webpack-cli、react-scripts等),确保版本兼容。降级Node.js方案:将Node.js版本降级到16.x LTS版本(使用OpenSSL 1.1.1,无此兼容性问题)
若使用nvm版本管理器:nvm install 16 nvm use 16
内容的提问来源于stack exchange,提问作者Abhijith Mohan
相关产品推荐
相关产品推荐

