【问题标题】:Node.js 17.0.1 Gatsby error - "digital envelope routines::unsupported ... ERR_OSSL_EVP_UNSUPPORTED" [duplicate]Node.js 17.0.1 Gatsby 错误 - “数字信封例程::不支持 ... ERR_OSSL_EVP_UNSUPPORTED”
【发布时间】:2021-12-08 09:50:40
【问题描述】:

我正在建立一个Gatsby 网站。我将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,它可以正常工作,并且构建将成功。我该如何解决这个问题?

通过谷歌搜索,这可能是一个类似的问题: Error: error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt #48

【问题讨论】:

标签: node.js gatsby


【解决方案1】:

这可能会有所帮助。在 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"
}

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

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

【讨论】:

  • 对于 VUE,它应该说 export 而不是 SET
  • 我们如何在 Cordova 项目或 Ionic 项目中做到这一点?
  • 角度怎么样?
  • 它适用于我的 vue.js。谢谢
【解决方案2】:

Gatsby 必须使用 algorithm or key size,这在 OpenSSL 3.0 中默认不再允许。

更新⚠️

这很可能是 webpack 问题 - https://github.com/webpack/webpack/issues/14532

他们已经在版本 5.61.0 中发布了一个修复程序 - https://github.com/webpack/webpack/releases/tag/v5.61.0 - 所以升级 webpack 应该也能解决这个问题

webpack 团队的成员has stated 他们不打算将修复程序反向移植到 webpack 4,所以如果你使用 webpack 4,你可能需要先升级到 webpack 5。


来自Node.js 17's announcement post

如果您在使用 Node.js 17 的应用程序中遇到 ERR_OSSL_EVP_UNSUPPORTED 错误,则很可能您的应用程序或您正在使用的模块正在尝试使用 OpenSSL 默认不再允许的算法或密钥大小3.0。已添加新的 command-line option--openssl-legacy-provider 以恢复为旧提供程序,作为这些收紧限制的临时解决方法。

在终端上运行它可能看起来像:

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

您也可以通过NODE_OPTIONS 环境变量传递它。

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

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

【讨论】:

  • 这个命令确实消除了错误: node --openssl-legacy-provider ./node_modules/.bin/gatsby build 非常感谢!这是否意味着将来要由 Gatsby 团队(甚至它所依赖的任何模块)来解决这个问题?
  • 是的,从您发布的错误来看,我无法确定是直接 gatsby 还是他们正在使用的模块。我想他们会在不久的将来为此发布错误修复版本。
【解决方案3】:

快速修复:在你的 React 项目的终端中运行它。

export NODE_OPTIONS=--openssl-legacy-provider

【讨论】:

  • 在这里使用节点 v17 为 Mastodon 服务器工作。谢谢!
  • 那去哪儿了?在脚本文件中?在终端中手动?应该在什么时候应用?在什么情况下?之后应该在那个终端运行什么? “在 React 项目的终端中运行” 是什么意思?在什么环境下?在Visual Studio Code 上下文中?还有什么?你能详细说明吗?请通过editing (changing) your answer 回复,而不是在 cmets 中(without "Edit:"、"Update:" 或类似的 - 答案应该看起来像是今天写的)。
【解决方案4】:

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

  • 卸载 Node.js

  • 然后下载并安装 16.13.0。

【讨论】:

    【解决方案5】:

    Rajiv's approach 似乎是一种解决方法,但 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"
      },
    

    【讨论】:

      【解决方案6】:

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

      1. 我刚刚将本地的 Node.js 版本降级到 14
      2. Docker 图像替换为版本14.18.1。早些时候是Alpine Linux

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

      【讨论】:

        【解决方案7】:

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

        1. 降级 Node.js

        2. node_modules\react-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);

        【讨论】:

          【解决方案8】:

          此问题随 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"
          }
          

          【讨论】:

            【解决方案9】:

            这确实解决了我的服务器启动问题:

            在此处提到的文件夹中: node_modules\react-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);
            

            【讨论】:

            【解决方案10】:

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

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

            【讨论】:

            • 重新“控制面板”:在 Windows 上?
            猜你喜欢
            • 2021-12-11
            • 2021-12-10
            • 2023-03-12
            • 2021-12-31
            • 1970-01-01
            • 2022-06-22
            • 1970-01-01
            • 2022-01-02
            相关资源
            最近更新 更多