概述
使用若依框架,启动UI执行命令npm run dev时报错误:Error: error:0308010C:digital envelope routines::unsupported
INFO Starting development server... 95% emitting CompressionPlugin ERROR Error: error:0308010C:digital envelope routines::unsupported Error: error:0308010C:digital envelope routines::unsupported at new Hash (node:internal/crypto/hash:71:19) at Object.createHash (node:crypto:133:10) at D:\Project\RuoYi\ruoyi-ui\node_modules\compression-webpack-plugin\dist\index.js:243:42 at CompressionPlugin.compress (D:\Project\RuoYi\ruoyi-ui\node_modules\compression-webpack-plugin\dist\index.js:284:9) at D:\Project\RuoYi\ruoyi-ui\node_modules\compression-webpack-plugin\dist\index.js:305:12 at _next1 (eval at create (D:\Project\RuoYi\ruoyi-ui\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:14:17) at eval (eval at create (D:\Project\RuoYi\ruoyi-ui\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:33:1) at D:\Project\RuoYi\ruoyi-ui\node_modules\copy-webpack-plugin\dist\index.js:91:9
分析
因为 nodeJs V17 版本发布了 OpenSSL3.0 对算法和秘钥大小增加了更为严格的限制,nodeJs v17 之前版本没影响,但 V17 和之后版本会出现这个错误。 我的node版本是v18.12.0
解决方案
解决方式(仅限 windows):
在项目中 package.json 的 scripts 中新增 SET NODE_OPTIONS=--openssl-legacy-provider
添加前:
"scripts": { "dev": "vue-cli-service serve", "build:prod": "vue-cli-service build", "build:stage": "vue-cli-service build --mode staging", "preview": "node build/index.js --preview", "lint": "eslint --ext .js,.vue src" },
添加后:
"scripts": { "dev": "SET NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve", "build:prod": "SET NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service build", "build:stage": "vue-cli-service build --mode staging", "preview": "node build/index.js --preview", "lint": "eslint --ext .js,.vue src" },