一、问题
因为项目需要将
node
版本从v14.17.0
升级到v20.9.1
了,然后启动项目报错
报错有些多,直接省略部分
building 2/2 modules 0 activeError: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:79:19)
at Object.createHash (node:crypto:139:10)
...
10% building 2/5 modules 3 active ...rains\IDEA\IdeaProjects\lz-safety\LZSafety-UI\node_modules@vue\cli-service\node_modules\webpack-dev-server\client\index.js?http://localhost:3200n
ode:internal/crypto/hash:79
this[kHandle] = new _Hash(algorithm, xofLen, algorithmId, getHashCache());
^
Error: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:79:19)
at Object.createHash (node:crypto:139:10)
...
opensslErrorStack: [
'error:03000086:digital envelope routines::initialization error',
'error:0308010C:digital envelope routines::unsupported'
],
library: 'digital envelope routines',
reason: 'unsupported',
code: 'ERR_OSSL_EVP_UNSUPPORTED'
}
Node.js v20.19.1
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
原因大致就是 Node.js 版本升级后,OpenSSL 安全策略加强导致的。通俗点说就是
Webpack 4
默认使用MD5 哈希算法
,但Node.js 17+
版本默认禁用了弱哈希算法(如 MD5、SHA-1)项目可能使用了较旧的
Webpack
或Vue CLI
版本(如 Webpack 4),与新的 Node.js 版本不兼容
二、解决
1、修改启动脚本。
2、升级Webpack 和相关依赖。
3、将Node.js 版本降级。
单纯启动个项目,所以采用方案一
找到项目的
package.json
文件,修改serve选项(控制项目启动),build(打包项目的)
修改前 | 修改后 |
---|---|
![]() |
![]() |
修改为以下代码
bash
"serve": "set NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve",
"build": "set NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service build",
启动项目,直接运行成功了