node升级到20导致若依项目启动失败

问题描述:

node升级到20导致若依项目启动失败

报错原因:

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

报错信息

> openai@3.8.3 dev     
> vue-cli-service serve

Browserslist: caniuse-lite is outdated. Please run:
  npx update-browserslist-db@latest
  Why you should do it regularly: https://github.com/browserslist/update-db#readme
 INFO  Starting development server...
10% building 2/5 modules 3 active ...e\pie-server\ruoyi-ui-springboot\node_modules\@vue\cli-plugin-eslint\node_modules\eslint-loader\index.js??ref--13-0!D:\LocalCode\pie-server\ruoyi-ui-springboot\src\main.jsError: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:80:19)
    at Object.createHash (node:crypto:139:10)
    at module.exports (D:\LocalCode\pie-server\ruoyi-ui-springboot\node_modules\webpack\lib\util\createHash.js:135:53)
    at NormalModule._initBuildHash (D:\LocalCode\pie-server\ruoyi-ui-springboot\node_modules\webpack\lib\NormalModule.js:417:16)
    at handleParseError (D:\LocalCode\pie-server\ruoyi-ui-springboot\node_modules\webpack\lib\NormalModule.js:471:10)
    at D:\LocalCode\pie-server\ruoyi-ui-springboot\node_modules\webpack\lib\NormalModule.js:503:5
    at D:\LocalCode\pie-server\ruoyi-ui-springboot\node_modules\webpack\lib\NormalModule.js:358:12
    at D:\LocalCode\pie-server\ruoyi-ui-springboot\node_modules\loader-runner\lib\LoaderRunner.js:373:3
    at iterateNormalLoaders (D:\LocalCode\pie-server\ruoyi-ui-springboot\node_modules\loader-runner\lib\LoaderRunner.js:214:10)
    at iterateNormalLoaders (D:\LocalCode\pie-server\ruoyi-ui-springboot\node_modules\loader-runner\lib\LoaderRunner.js:221:10)
    at D:\LocalCode\pie-server\ruoyi-ui-springboot\node_modules\loader-runner\lib\LoaderRunner.js:236:3
    at runSyncOrAsync (D:\LocalCode\pie-server\ruoyi-ui-springboot\node_modules\loader-runner\lib\LoaderRunner.js:130:11)
    at iterateNormalLoaders (D:\LocalCode\pie-server\ruoyi-ui-springboot\node_modules\loader-runner\lib\LoaderRunner.js:232:2)
    at Array.<anonymous> (D:\LocalCode\pie-server\ruoyi-ui-springboot\node_modules\loader-runner\lib\LoaderRunner.js:205:4)
    at Storage.finished (D:\LocalCode\pie-server\ruoyi-ui-springboot\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:55:16)
    at D:\LocalCode\pie-server\ruoyi-ui-springboot\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:91:9
node:internal/crypto/hash:80
  this[kHandle] = new _Hash(algorithm, xofLen, algorithmId, getHashCache());

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:80:19)
    at Object.createHash (node:crypto:139:10)
    at module.exports (D:\LocalCode\pie-server\ruoyi-ui-springboot\node_modules\webpack\lib\util\createHash.js:135:53)
    at NormalModule._initBuildHash (D:\LocalCode\pie-server\ruoyi-ui-springboot\node_modules\webpack\lib\NormalModule.js:417:16)
    at handleParseError (D:\LocalCode\pie-server\ruoyi-ui-springboot\node_modules\webpack\lib\NormalModule.js:471:10)
    at D:\LocalCode\pie-server\ruoyi-ui-springboot\node_modules\webpack\lib\NormalModule.js:503:5
    at D:\LocalCode\pie-server\ruoyi-ui-springboot\node_modules\webpack\lib\NormalModule.js:358:12
    at D:\LocalCode\pie-server\ruoyi-ui-springboot\node_modules\loader-runner\lib\LoaderRunner.js:373:3
    at iterateNormalLoaders (D:\LocalCode\pie-server\ruoyi-ui-springboot\node_modules\loader-runner\lib\LoaderRunner.js:214:10)
    at Array.<anonymous> (D:\LocalCode\pie-server\ruoyi-ui-springboot\node_modules\loader-runner\lib\LoaderRunner.js:205:4)
    at Storage.finished (D:\LocalCode\pie-server\ruoyi-ui-springboot\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:55:16)
    at D:\LocalCode\pie-server\ruoyi-ui-springboot\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:91:9
    at D:\LocalCode\pie-server\ruoyi-ui-springboot\node_modules\graceful-fs\graceful-fs.js:123:16
    at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read/context:68:3) {
  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.12.0

解决方法

在项目中 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"
  },

项目启动成功

PS D:\LocalCode\pie-server\ruoyi-ui-springboot> npm run dev

> openai@3.8.3 dev
> SET NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve

Browserslist: caniuse-lite is outdated. Please run:
  npx update-browserslist-db@latest
  Why you should do it regularly: https://github.com/browserslist/update-db#readme
 INFO  Starting development server...
98% after emitting CopyPlugin

 DONE  Compiled successfully in 32214ms                                                                                                                                                                  13:27:15

  App running at:
  - Local:   http://localhost:8080/
  - Network: http://172.20.10.3:8080/

  Note that the development build is not optimized.
  To create a production build, run npm run build. 


  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值