问题描述
vue2 启动项目时报错如下:
> npm run serve
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 (C:\Users\Administrator\Desktop\SupplyChain_finish\front\node_modules\webpack\lib\util\createHash.js:135:53)
at NormalModule._initBuildHash (C:\Users\Administrator\Desktop\SupplyChain_finish\front\node_modules\webpack\lib\NormalModule.js:417:16)
at handleParseError (C:\Users\Administrator\Desktop\SupplyChain_finish\front\node_modules\webpack\lib\NormalModule.js:471:10)
at C:\Users\Administrator\Desktop\SupplyChain_finish\front\node_modules\webpack\lib\NormalModule.js:503:5
at C:\Users\Administrator\Desktop\SupplyChain_finish\front\node_modules\webpack\lib\NormalModule.js:358:12
at C:\Users\Administrator\Desktop\SupplyChain_finish\front\node_modules\loader-runner\lib\LoaderRunner.js:373:3
at iterateNormalLoaders (C:\Users\Administrator\Desktop\SupplyChain_finish\front\node_modules\loader-runner\lib\LoaderRunner.js:214:10)
at Storage.finished (C:\Users\Administrator\Desktop\SupplyChain_finish\front\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:55:16)
at C:\Users\Administrator\Desktop\SupplyChain_finish\front\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:91:9
at C:\Users\Administrator\Desktop\SupplyChain_finish\front\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.js V17 版本中最近发布的 OpenSSL3.0, 而 OpenSSL3.0 对允许算法和密钥大小增加了严格的限制。本项目是在 Node.js 16.14.0 版本下创建,而运行的版本是 node.js V18 版本,导致出现 OpenSSL 3.0 的版本兼容性问题。
解决方案
方法一
从其他文章找到的办法,但是本人实测不行,原因未知,大概是电脑差异
# 使用win+R,输入cmd,在终端中输入如下命令:
> set NODE_OPTIONS=--openssl-legacy-provider
方法二
修改 vue 项目的 package.json 文件,添加 "serve": "set NODE_OPTIONS=\"--openssl-legacy-provider\" & npm run dev\n"
,如下:
"scripts": {
"dev": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"serve": "set NODE_OPTIONS=\"--openssl-legacy-provider\" & npm run dev\n"
},
方法三
降低自己 nodejs 的版本保持和 vue 工程的中 nodejs 版本一致即可
标签:Node,node,Administrator,finish,js,版本,兼容性问题,front,Desktop From: https://www.cnblogs.com/binbingg/p/17089073.html