我正在建立一个盖茨比网站。我将 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)
"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)
Byu*_*usa 199
快速修复:在 React 项目内的终端中运行此命令。
export NODE_OPTIONS=--openssl-legacy-provider
Run Code Online (Sandbox Code Playgroud)
rom*_*lem 106
这很可能是 webpack 的问题。
\n\n将 webpack 升级到上面列出的版本之外应该可以解决该问题。
\n当最初注意到该错误时,请参阅此问题以进行进一步讨论:
\n\nmd4
最终,这与使用哈希的webpack 有关,他们的解决方案是切换到使用 WASM 实现md4
,而不是节点的内置算法(其中节点依赖于 OpenSSL,因此会出现错误)。
请注意,虽然 webpack 团队的一名成员表示他们不打算将修复程序反向移植到 webpack 4,但v4.47.0版本仍然包含一个自定义md4
实现来支持 Node 18 及更高版本。
Gatsby / Gatsby 中使用的工具必须使用OpenSSL 3.0 默认情况下不再允许的加密算法或密钥大小。
\n\n\n\n如果您
\nERR_OSSL_EVP_UNSUPPORTED
在使用 Node.js 17 的应用程序中遇到错误,则您的应用程序或您正在使用的模块可能正在尝试使用不再允许的算法或密钥大小默认情况下使用 OpenSSL 3.0。添加了一个新的命令行选项来--openssl-legacy-provider
恢复到旧提供程序,作为这些严格限制的临时解决方法。
在终端上运行它可能看起来像:
\nnode --openssl-legacy-provider ./node_modules/.bin/gatsby build\n
Run Code Online (Sandbox Code Playgroud)\n您还可以通过NODE_OPTIONS环境变量传递它。
\n因此,如果您想继续使用 NPM 脚本,可以将build
脚本更改为:
// 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。
小智 12
我认为对于新的 Node.js 更新后遇到的这个错误有两种解决方案。
降级 Node.js
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)