Featured image of post vue启动项目时报opensslErrorStack错误

vue启动项目时报opensslErrorStack错误

错误描述

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:71:19)
    at Object.createHash (node:crypto:130:10)
    at module.exports (/Volumes/Yuan/dftt/dn/shakeu/h5/node_modules/webpack/lib/util/createHash.js:135:53)
    at NormalModule._initBuildHash (/Volumes/Yuan/dftt/dn/shakeu/h5/node_modules/webpack/lib/NormalModule.js:417:16)
    at handleParseError (/Volumes/Yuan/dftt/dn/shakeu/h5/node_modules/webpack/lib/NormalModule.js:471:10)
    at /Volumes/Yuan/dftt/dn/shakeu/h5/node_modules/webpack/lib/NormalModule.js:503:5
    at /Volumes/Yuan/dftt/dn/shakeu/h5/node_modules/webpack/lib/NormalModule.js:358:12
    at /Volumes/Yuan/dftt/dn/shakeu/h5/node_modules/loader-runner/lib/LoaderRunner.js:373:3
    at iterateNormalLoaders (/Volumes/Yuan/dftt/dn/shakeu/h5/node_modules/loader-runner/lib/LoaderRunner.js:214:10)
    at Array.<anonymous> (/Volumes/Yuan/dftt/dn/shakeu/h5/node_modules/loader-runner/lib/LoaderRunner.js:205:4)
    at Storage.finished (/Volumes/Yuan/dftt/dn/shakeu/h5/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:55:16)
    at /Volumes/Yuan/dftt/dn/shakeu/h5/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:91:9
    at /Volumes/Yuan/dftt/dn/shakeu/h5/node_modules/graceful-fs/graceful-fs.js:123:16
    at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3) {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

错误原因

原因在于node版本过高,node在 16.18 开始使用OpenSSl3.0对算法和密钥大小增加了严格限制。故而node16.18+,node17+都可能会出现这个问题。

处理方式

方式一:

降级node版本,注意这里如果你是 16 的版本,是以 16.18 为分界线的,这里就自行卸载重装就好。

方式二:

添加环境参数 NODE_OPTIONS=--openssl-legacy-provider

这里可以在运行时临时添加环境变量 export NODE_OPTIONS=--openssl-legacy-provider 使用,也可以直接添加到环境变量文件中长期解决问题。
临时处理还可以修改 package.json 文件,在运行的时候追加这个参数,但这里也会有些问题,如果有其它成员的版本比较低的时候也出现报错。