节点.js 17.0.1 盖茨比错误 - "digital envelope routines::unsupported ... ERR_OSSL_EVP_UNSUPPORTED"



我正在建造一个盖茨比网站。我将Node.js升级到v17.0.1,当我运行构建时,出现了一个错误:

Error: digital envelope routines::unsupported
opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
library: 'digital envelope routines',
reason: 'unsupported',
code: 'ERR_OSSL_EVP_UNSUPPORTED'

如果我把它降级到v16,它运行良好,构建就会成功。我该怎么解决这个问题?

从谷歌搜索来看,这可能是一个类似的问题:错误:错误:06065064:数字信封例程:EVP_DecryptFinal_ex:错误解密#48

这可能会有所帮助。将这些脚本添加到package.json文件中。

反应:

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

如果您在Windows上并且使用React.js,则可以在脚本中使用set而不是export,如下所示:

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

"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"
},

如果您在Windows上并且使用Vue.js,则可以在脚本中使用set而不是export,如下所示:

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

"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"
},

角度:

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

快速修复:在React项目内的终端中运行此程序。

export NODE_OPTIONS=--openssl-legacy-provider

更新⚠️

这是一个网络包问题(很可能)

  • https://github.com/webpack/webpack/issues/14532

他们已经在版本5.61.0中发布了修复程序,因此将webpack升级到版本5.61.0或更高版本也应该可以解决这个问题。

  • https://github.com/webpack/webpack/releases/tag/v5.61.0

webpack团队的一名成员表示,他们不打算将修复程序备份到webpack 4,因此,如果您使用的是webpack4,则可能需要先升级到webpack5。

该问题与使用md4哈希的webpack有关,他们的解决方案是切换到使用md4算法的WASM实现,而不是节点的内置(其中节点依赖于OpenSSL,因此出现错误)。


原始响应:

Gatsby/Gatsby中使用的工具必须使用OpenSSL 3.0默认情况下不再允许的加密算法或密钥大小。

来自Node.js 17的公告帖子:

如果你在Node.js 17的应用程序中遇到ERR_OSSL_EVP_UNSUPPORTED错误,很可能你的应用程序或你正在使用的模块试图使用OpenSSL 3.0默认情况下不再允许的算法或密钥大小。添加了一个新的命令行选项--openssl-legacy-provider,以恢复到旧的提供程序,作为这些严格限制的临时解决方案。

在终端上运行此操作可能看起来像:

node --openssl-legacy-provider ./node_modules/.bin/gatsby build

也可以通过NODE_OPTIONS环境变量传递此信息。

因此,如果您想继续使用NPM脚本,可以将build脚本更改为:

// package.json
{
"scripts": {
"build": "NODE_OPTIONS=--openssl-legacy-provider gatsby build"
}
}

此问题随Node.js 17的新更新而来。在React中,您可以将package.json文件中的脚本属性更改为:

"scripts": {
"start": "react-scripts --openssl-legacy-provider start",
"build": "react-scripts --openssl-legacy-provider build",
"test": "react-scripts test",
"eject": "react-scripts eject"
}

我也遇到了同样的问题,所以我只是降级了Node.js版本:

  • 卸载Node.js

  • 然后下载并安装16.13.0。

我认为在新的Node.js更新后,我们遇到的这个错误有两种解决方案。

  1. 降级Node.js

  2. node_modules\areact scripts\config\webpack.config.js-您应该将此代码添加到您在此处找到的.js文件中:

    const crypto = require("crypto");
    const crypto_orig_createHash = crypto.createHash;
    crypto.createHash = algorithm => crypto_orig_createHash(algorithm == "md4" ? "sha256" : algorithm);

将其用作Vue.js 3和Node.js v17.0.1:的构建命令

cross-env NODE_OPTIONS='--openssl-legacy-provider' vue-cli-service build"

Rajiv的方法似乎是一种正确的变通方法,但语法在Vue.js中对我不起作用;SET":

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

我已经通过控制面板卸载了Node.js 17.0.1版本。

然后我从nodejs.org下载了Node.js版本16.13.1并安装了它,然后React Native启动并构建得很好。

我在17.3.0版本中遇到过类似的问题。

  1. 我已经卸载了Node.js,安装了16.13.0版本并重新启动
  2. 通过在新航站楼运行,它得到了修复

我在服务器上的Angular应用程序也遇到了同样的问题

  1. 我刚刚将Node.js的本地版本降级为14
  2. Docker镜像已替换为14.18.1版本。早期是Alpine Linux

您可以在Node.js的最新发布文档中找到更多详细信息。

虽然使用--openssl-legacy-provider进行修补更像是一种黑客攻击,但真正的解决方案是修复Vue.js、React等中OpenSSL密钥大小的使用。;暂时的解决方法可能是使用Node.js的旧版本。

但我建议不要降级Node.js;而是安装NVM(main/win:NVM-windows/nodist/nvs,最后一个是跨平台的),并根据需要在版本之间切换。

我认为您应该降级Node.js或使用nvm在Node.js版本之间切换。我做到了,React运行良好。

相关内容

最新更新