0


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算法

参考链接:

标签: javascript node.js

本文转载自: https://blog.csdn.net/qian____/article/details/130485011
版权归原作者 qian____ 所有, 如有侵权,请联系我们删除。

“Error: error:0308010C:digital envelope routines::unsupported”的评论:

还没有评论