Vue学习笔记之opensslErrorStack: [ ‘error:03000086:digital envelope routines::initialization error‘ ]的问题
0x00 概述
前端Vue项目启动报错如下:
/** <s> [webpack.Progress] 10% building 0/1 entries 0/0 dependencies 0/0 modules node:internal/crypto/hash:67 this[kHandle] = new _Hash(algorithm, xofLen); ^ Error: error:0308010C:digital envelope routines::unsupported at new Hash (node:internal/crypto/hash:67:19) at Object.createHash (node:crypto:130:10) at BulkUpdateDecorator.hashFactory (/app/node_modules/webpack/lib/util/createHash.js:155:18) at BulkUpdateDecorator.update (/app/node_modules/webpack/lib/util/createHash.js:46:50) at OriginalSource.updateHash (/app/node_modules/webpack-sources/lib/OriginalSource.js:131:8) at NormalModule._initBuildHash (/app/node_modules/webpack/lib/NormalModule.js:888:17) at handleParseResult (/app/node_modules/webpack/lib/NormalModule.js:954:10) at /app/node_modules/webpack/lib/NormalModule.js:1048:4 at processResult (/app/node_modules/webpack/lib/NormalModule.js:763:11) at /app/node_modules/webpack/lib/NormalModule.js:827:5 { opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ], library: 'digital envelope routines', reason: 'unsupported', code: 'ERR_OSSL_EVP_UNSUPPORTED' } command terminated with exit code 1 */
0x01 NodeJS版本过高
将NodeJS版本版本降低到项目制定的版本;
在重新安装之前,一定要卸载干净,具体的卸载方式可以参考这个链接:
windows如何把已安装的nodejs高版本降级为低版本(图文教程)
0x02 添加项目启动参数
该方法不降级NodeJS,适用于降级也无效的情况下,需要在npm run serve项目启动前声明条件变量;
windows在命令行依次输入如下2个命令:
$env:NODE_OPTIONS="--openssl-legacy-provider"
npm start
Linux:
NODE_OPTIONS=--openssl-legacy-provider npm start
或者打开项目package.json文件,修改如下:
"serve": "set NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve",
"build": "set NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service build",
Linux或者Mac环境,使用以上有时候没效果,这时候只需要在命令行输入如下,再运行npm 操作就可
export NODE_OPTIONS=--openssl-legacy-provider
0x03 参考
Webpack build failing with ERR_OSSL_EVP_UNSUPPORTED [duplicate]