Node.js 17.0.1 Gatsby 错误 - “数字信封例程::不支持... ERR_OSSL_EVP_UNSUPPORTED”

Dav*_*vid 185 node.js 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'
Run Code Online (Sandbox Code Playgroud)

如果我将其降级到 v16,它可以正常工作,并且构建将会成功。我怎样才能解决这个问题?

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

Raj*_*ngh 299

这可能会有所帮助。将这些脚本添加到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"
}
Run Code Online (Sandbox Code Playgroud)

如果您已打开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"
}
Run Code Online (Sandbox Code Playgroud)

或者

"scripts": {
    "start": "react-scripts --openssl-legacy-provider start",
    "build": "react-scripts --openssl-legacy-provider build",
}
Run Code Online (Sandbox Code Playgroud)

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"
},
Run Code Online (Sandbox Code Playgroud)

如果您已打开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"
},
Run Code Online (Sandbox Code Playgroud)

或者

"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"
},
Run Code Online (Sandbox Code Playgroud)

角度:

"scripts": {
 "start": "set NODE_OPTIONS=--openssl-legacy-provider  && gulp buildDev && ng serve ",
 "publish": "set NODE_OPTIONS=--openssl-legacy-provider  && gulp build && ng build --prod",
},
Run Code Online (Sandbox Code Playgroud)

  • 他,非常感谢这个。我有一个简单的问题,到底是什么导致了这个问题。 (2认同)
  • 只需在项目根目录中运行此命令即可。导出 NODE_OPTIONS=--openssl-legacy-provider (2认同)
  • 这有效,但我仍然不明白问题是什么。是什么原因造成的呢? (2认同)

Byu*_*usa 199

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

export NODE_OPTIONS=--openssl-legacy-provider
Run Code Online (Sandbox Code Playgroud)

  • 那会去哪里?在脚本文件中?在终端中手动?应该什么时候应用?在什么背景下?之后应该在该终端中运行什么?*“在 React 项目内的终端中运行它”* 是什么意思?在什么环境下?在 [Visual Studio Code](https://en.wikipedia.org/wiki/Visual_Studio_Code) 上下文中?还有别的事吗?你能详细说明一下吗?请通过[编辑(更改)您的答案](https://stackoverflow.com/posts/70116509/edit) 进行回复,而不是在评论中回复(***没有***“编辑:”、“更新:”或类似 - 答案应该看起来像今天写的一样)。 (6认同)
  • 节点:NODE_OPTIONS 中不允许 --openssl-legacy-provider (5认同)
  • 在这里使用 Mastodon 服务器的 Node v17 工作。谢谢! (4认同)
  • 不知道它做了什么,但它有效。有人可以解释一下吗?我在源代码管理中没有看到任何内容,所以不太确定这里发生了什么 (3认同)
  • 我在评论中没有写什么? (2认同)

rom*_*lem 106

这很可能是 webpack 的问题。

\n
    \n
  • 如果您使用的是版本 4,则该问题已在版本 4.47.0 ( release ) 中修复。
  • \n
  • 如果您使用的是版本 5,则该问题已在版本 5.61.0 ( release ) 中修复。
  • \n
\n

将 webpack 升级到上面列出的版本之外应该可以解决该问题。

\n

当最初注意到该错误时,请参阅此问题以进行进一步讨论:

\n\n

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

\n

请注意,虽然 webpack 团队的一名成员表示他们不打算将修复程序反向移植到 webpack 4,但v4.47.0版本仍然包含一个自定义md4实现来支持 Node 18 及更高版本

\n
\n

原始回复:

\n

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

\n

来自Node.js 17 的公告帖子

\n
\n

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

\n
\n

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

\n
node --openssl-legacy-provider ./node_modules/.bin/gatsby build\n
Run Code Online (Sandbox Code Playgroud)\n

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

\n

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

\n
// package.json\n{\n  "scripts": {\n    "build": "NODE_OPTIONS=--openssl-legacy-provider gatsby build"\n  }\n}\n
Run Code Online (Sandbox Code Playgroud)\n


小智 28

这个问题是在 Node.js 17 的新更新中出现的。在React中,您可以将package.json文件中的 script 属性更改为:

"scripts": {
    "start": "react-scripts --openssl-legacy-provider start",
    "build": "react-scripts --openssl-legacy-provider build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
}
Run Code Online (Sandbox Code Playgroud)


小智 20

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

  • 卸载 Node.js

  • 然后下载并安装16.13.0。

  • 您还可以利用 nvm 在节点版本之间切换 (9认同)
  • 我强烈建议在每个平台上使用 nvm,因为由于某些原因,您必须从一个平台切换到另一个平台...手动管理它比卸载等容易得多... (2认同)

小智 12

我认为对于新的 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);
    Run Code Online (Sandbox Code Playgroud)


小智 6

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

cross-env NODE_OPTIONS='--openssl-legacy-provider' vue-cli-service build"
Run Code Online (Sandbox Code Playgroud)


小智 5

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"
  },
Run Code Online (Sandbox Code Playgroud)