Error: error:0308010C:digital envelope routines::unsupported
问题描述:
使用 npm run dev 或者 yarn run dev 时
报错:Error: error:0308010C:digital envelope routines::unsupported
PS D:\Project\dlspeed_all\GS-IMS\ruoyi-ui> npm run dev
> ruoyi-vue-plus@4.7.0 dev
> vue-cli-service serve
INFO Starting development server...
10% building 2/4 modules 2 active D:\Project\dlspeed_all\GS-IMS\ruoyi-ui\node_modules\webpack\hot\dev-server.jsError: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:69:19)
at Object.createHash (node:crypto:133:10)
at module.exports (D:\Project\dlspeed_all\GS-IMS\ruoyi-ui\node_modules\webpack\lib\util\createHash.js:135:53)
at NormalModule._initBuildHash (D:\Project\dlspeed_all\GS-IMS\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:417:16)
at handleParseError (D:\Project\dlspeed_all\GS-IMS\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:471:10)
at D:\Project\dlspeed_all\GS-IMS\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:503:5
at D:\Project\dlspeed_all\GS-IMS\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:358:12
at D:\Project\dlspeed_all\GS-IMS\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:373:3
at iterateNormalLoaders (D:\Project\dlspeed_all\GS-IMS\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:214:10)
at iterateNormalLoaders (D:\Project\dlspeed_all\GS-IMS\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:221:10)
at D:\Project\dlspeed_all\GS-IMS\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:236:3
at runSyncOrAsync (D:\Project\dlspeed_all\GS-IMS\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:130:11)
at iterateNormalLoaders (D:\Project\dlspeed_all\GS-IMS\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:232:2)
at Array.<anonymous> (D:\Project\dlspeed_all\GS-IMS\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:205:4)
at Storage.finished (D:\Project\dlspeed_all\GS-IMS\ruoyi-ui\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:55:16)
at D:\Project\dlspeed_all\GS-IMS\ruoyi-ui\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:91:9
10% building 2/5 modules 3 active ...loader\lib\index.js!D:\Project\dlspeed_all\GS-IMS\ruoyi-ui\node_modules\eslint-loader\index.js??ref--13-0!D:\Project\dlspeed_all\GS-IMS\ruoyi-ui\src\main.js n
ode:internal/crypto/hash:69
this[kHandle] = new _Hash(algorithm, xofLen);
^
Error: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:69:19)
at Object.createHash (node:crypto:133:10)
at module.exports (D:\Project\dlspeed_all\GS-IMS\ruoyi-ui\node_modules\webpack\lib\util\createHash.js:135:53)
at NormalModule._initBuildHash (D:\Project\dlspeed_all\GS-IMS\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:417:16)
at handleParseError (D:\Project\dlspeed_all\GS-IMS\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:471:10)
at D:\Project\dlspeed_all\GS-IMS\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:503:5
at D:\Project\dlspeed_all\GS-IMS\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:358:12
at D:\Project\dlspeed_all\GS-IMS\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:373:3
at iterateNormalLoaders (D:\Project\dlspeed_all\GS-IMS\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:214:10)
at Array.<anonymous> (D:\Project\dlspeed_all\GS-IMS\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:205:4)
at Storage.finished (D:\Project\dlspeed_all\GS-IMS\ruoyi-ui\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:55:16)
at D:\Project\dlspeed_all\GS-IMS\ruoyi-ui\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:91:9
at D:\Project\dlspeed_all\GS-IMS\ruoyi-ui\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 v18.17.1
报错原因:
因为 node.js V17版本 中最近发布的 OpenSSL3.0, 而 OpenSSL3.0 对允许算法和密钥大小增加了严格的限制
解决方案:
修改 package.json 文件
在相关构建命令之前加入 set NODE_OPTIONS=--openssl-legacy-provider
“scripts”: {
“dev”: “set NODE_OPTIONS=–openssl-legacy-provider & node build/dev-server.js”,
“serve”: “set NODE_OPTIONS=–openssl-legacy-provider & vue-cli-service serve”,
“build”: “set NODE_OPTIONS=–openssl-legacy-provider & vue-cli-service build”,
“build:report”: “set NODE_OPTIONS=–openssl-legacy-provider & vue-cli-service build --report”
},
例:如果你使用的命令是 npm run dev
,那么就在 scripts 命令下的 dev 命令前面加
如果是 Linux 或者 WSL 环境,请加入 export NODE_OPTIONS=--openssl-legacy-provider