导入Vue项目启动报Error: error:0308010C:digital envelope routines::unsupported

  • Post author:
  • Post category:vue


错误信息:

启动(npm run dev)和打包时(npm run build:prod)报出如下错误,

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:71:19)
    at Object.createHash (node:crypto:133:10)
    at module.exports (D:\wwt\litemall\litemall-admin\node_modules\webpack\lib\util\createHash.js:135:53)
    at NormalModule._initBuildHash (D:\wwt\litemall\litemall-admin\node_modules\webpack\lib\NormalModule.js:417:16)
    at handleParseError (D:\wwt\litemall\litemall-admin\node_modules\webpack\lib\NormalModule.js:471:10)
    at D:\wwt\litemall\litemall-admin\node_modules\webpack\lib\NormalModule.js:503:5
    at D:\wwt\litemall\litemall-admin\node_modules\webpack\lib\NormalModule.js:358:12
    at D:\wwt\litemall\litemall-admin\node_modules\loader-runner\lib\LoaderRunner.js:373:3
    at iterateNormalLoaders (D:\wwt\litemall\litemall-admin\node_modules\loader-runner\lib\LoaderRunner.js:214:10)
    at Array.<anonymous> (D:\wwt\litemall\litemall-admin\node_modules\loader-runner\lib\LoaderRunner.js:205:4)
    at Storage.finished (D:\wwt\litemall\litemall-admin\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:55:16)
    at D:\wwt\litemall\litemall-admin\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:91:9
    at D:\wwt\litemall\litemall-admin\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'
}

问题原因:

查了下原因,主要NodeJs版本发布了OpenSSL3.0对算法和秘钥大小增加了更为严格的限制,nodeJs v17之前版本没影响,但V17和之后版本会出现这个错误。

解决方案亲试可行:

在package.json的scripts中新增SET NODE_OPTIONS=--openssl-legacy-provider
添加前:
"scripts": {
    "dev": "vue-cli-service serve",
    "build:prod": "vue-cli-service build"
  },
  
添加后
"scripts": {
    "dev": "SET NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve",
    "build:prod": "SET NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service build"
  },
 
 
注意:如果团队中node版本不一致,不要将该package.json提交。

然后启动正常运行:



版权声明:本文为wwt1996原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。