本文介绍: 我的配置nodev=> v19.8.1搜索了一番,在中搜到了解决方案

启动项目报错如下

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
windowscmdset NODE_OPTIONS=--openssl-legacy-provider
windows端PowerShell: $env:NODE_OPTIONS = "--openssl-legacy-provider"
担心影响其他使用到node的程序没有采用

方法三:

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

"scripts": {
    "start": "export SET NODE_OPTIONS=--openssl-legacy-provider &amp;&amp; react-scripts start",
    "build": "export SET NODE_OPTIONS=--openssl-legacy-provider &amp;&amp; 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 &amp;&amp; vue-cli-service serve",
    "build": "export NODE_OPTIONS=--openssl-legacy-provider &amp;&amp; vue-cli-service build",
    "lint": "export NODE_OPTIONS=--openssl-legacy-provider &amp;&amp; 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  &amp;&amp; gulp buildDev && ng serve ",
	"publish": "set NODE_OPTIONS=--openssl-legacy-provider  && gulp build && ng build --prod",
}

方法四:

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

参考链接:

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注