Error: error:0308010C:digital envelope routines::unsupported

启动项目时报错,如下:

node:internal/crypto/hash:71
  this[kHandle] = new _Hash(algorithm, xofLen);
                  ^

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:71:19)
    at Object.createHash (node:crypto:140:10)
{
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

出现这个错误的原因是,node版本太高,跟openssl不匹配,node官方也说明: Node.js v17.x, v18.x, and v19.x use OpenSSL v3.
我的配置:
node版本:node -v => v19.8.1
openssl版本:openssl version => LibreSSL 2.8.3

搜索了一番,在stackoverflow中搜到了解决方案。

方法一:

最简单
降低node版本,node<17以下即可,我这儿使用的nvm降低node到 v16.20.0,就可以正常启动项目了。

方法二:

设置node环境变量的参数: export NODE_OPTIONS=--openssl-legacy-provider
windows端cmd:set NODE_OPTIONS=--openssl-legacy-provider
windows端PowerShell: $env:NODE_OPTIONS = "--openssl-legacy-provider"
担心影响其他使用到node的程序,没有采用。

方法三:

跟上一种类似,只不过加入到启动项目的命令中
React:

"scripts": {
    "start": "export SET NODE_OPTIONS=--openssl-legacy-provider && react-scripts start",
    "build": "export SET NODE_OPTIONS=--openssl-legacy-provider && react-scripts build"
}
or
"scripts": {
    "start": "react-scripts --openssl-legacy-provider start",
    "build": "react-scripts --openssl-legacy-provider build",
}

Vue.js:

"scripts": {
    "serve": "export NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve",
    "build": "export NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service build",
    "lint": "export NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service lint"
}
or
"scripts": {
    "serve": "vue-cli-service --openssl-legacy-provider serve",
    "build": "vue-cli-service --openssl-legacy-provider build",
    "lint": "vue-cli-service --openssl-legacy-provider lint"
}

Angular:

"scripts": {
	"start": "set NODE_OPTIONS=--openssl-legacy-provider  && gulp buildDev && ng serve ",
	"publish": "set NODE_OPTIONS=--openssl-legacy-provider  && gulp build && ng build --prod",
}

方法四:

修改webpack版本,跟webpack中使用了md4哈希算法有关,在v5.61.0中使用了wasm实现的md4算法

  • https://github.com/webpack/webpack/releases/tag/v5.61.0
  • https://github.com/webpack/webpack/issues/14532
    or
    如果webpack版本大于5.54,可以尝试一下修改experiments.futureDefaults: trueoutput.hashFunction: 'xxhash64',我没有尝试
  • 配置hashFunction:https://webpack.js.org/configuration/output/#outputhashfunction
    但是更改webpack版本或者是修改output配置,也不一定就可以解决全部的问题,如果有别的node_modules包中,也使用了node的crypto.hash,那么还是会出问题,个人感觉还是降低node版本最划算。

参考链接:

  • https://www.jianshu.com/p/edbad6875b7e#fn2
  • https://stackoverflow.com/questions/69665222/node-js-17-0-1-gatsby-error-digital-envelope-routinesunsupported-err-os?answertab=scoredesc#tab-top
  • https://github.com/webpack/webpack/releases/tag/v5.61.0
  • https://github.com/webpack/webpack/issues/14532
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值