出现错误信息'digital envelope routines',原因为'不支持',代码为'ERR_OSSL_EVP_UNSUPPORTED'。

70
我在学习Next.js时,按照这里的网站文档https://nextjs.org/docs/api-reference/create-next-app使用npx create-next-app命令时出现了错误。一切都正常,直到我启动服务器时,错误信息如下:
$ npm run dev

> devto-clone@0.1.0 dev
> next dev

ready - started server on 0.0.0.0:3000, url: http://localhost:3000
info  - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:67:19)
    at Object.createHash (node:crypto:130:10)
    at BulkUpdateDecorator.hashFactory (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:138971:18)
    at BulkUpdateDecorator.update (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:138872:50)
    at OriginalSource.updateHash (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack-sources3\index.js:1:10264)
    at NormalModule._initBuildHash (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68468:17)
    at handleParseResult (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68534:10)
    at C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68628:4
    at processResult (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68343:11)
    at C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68407:5
Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:67:19)
    at Object.createHash (node:crypto:130:10)
    at BulkUpdateDecorator.hashFactory (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:138971:18)
    at BulkUpdateDecorator.update (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:138872:50)
    at OriginalSource.updateHash (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack-sources3\index.js:1:10264)
    at NormalModule._initBuildHash (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68468:17)
    at handleParseResult (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68534:10)
    at C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68628:4
    at processResult (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68343:11)
    at C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68407:5
node:internal/crypto/hash:67
  this[kHandle] = new _Hash(algorithm, xofLen);
                  ^

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:67:19)
    at Object.createHash (node:crypto:130:10)
    at BulkUpdateDecorator.hashFactory (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:138971:18)
    at BulkUpdateDecorator.update (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:138872:50)
    at OriginalSource.updateHash (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack-sources3\index.js:1:10264)
    at NormalModule._initBuildHash (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68468:17)
    at handleParseResult (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68534:10)
    at C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68628:4
    at processResult (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68343:11)
    at C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68407:5 {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

Node.js v17.0.1

package.json:

{
  "name": "devto-clone",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "next": "11.1.2",
    "react": "17.0.2",
    "react-dom": "17.0.2"
  },
  "devDependencies": {
    "eslint": "7.32.0",
    "eslint-config-next": "11.1.2"
  }
}
5个回答

142

我在这里找到了解决方案:https://github.com/webpack/webpack/issues/14532

  1. 如果使用 bash,只需在任何命令之前运行 NODE_OPTIONS=--openssl-legacy-provider

  2. NODE_OPTIONS=--openssl-legacy-provider 添加到 package.json。

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

编辑

在我的情况下,我正在使用Nodejs 17.0.1版本并引起了此错误。

首先,在GitBash Windows中任何命令之前,我使用此命令export NODE_OPTIONS=--openssl-legacy-provider来解决此问题。

但是,我认为这不是一种高效的方式,所以我所做的是:

  1. 卸载Nodejs 17.0.1
  2. 重新安装Nodejs 16.13.0版本
  3. 当我使用“yarn serve”启动服务器(我的另一个Vuejs项目)时,我遇到了另一个错误,我不记得这是什么,但在运行“yarn”和“yarn serve”之后,现在一切都可以正常工作

无法在Win10下运行。我收到了错误消息,指出找不到命令“export”,或者输入有误。 - Mavv3006
在Linux上为我工作。为了方便,我将其添加到我的.bashrc中进行导出。 - raphael
感谢您在最后一部分进行编辑。Node 16 对我来说是解决方案。 - Ricardo Vargas
适用于我。Windows 10 NodeJS 17.9.0 Angular 9。在运行ng serve时: "start": "SET NODE_OPTIONS=--openssl-legacy-provider && ng serve", - Roman Kuznetsov
1
抱歉 @ErickAdam,我刚看到你的消息。我使用的是 macOS。 - Ricardo Vargas
显示剩余4条评论

32

对于 MacOS 和 React Native:

"scripts": {
   "start": "NODE_OPTIONS=--openssl-legacy-provider react-native start",
}

1
它在Linux上也可以运行。我正在使用mix watch命令。 - Elikill58
如果在此之后地铁没有启动,则使用 npm start -- --reset-cache 清除缓存,它会起作用! - Wahas Ali Mughal
对于普通的React项目: "start": "NODE_OPTIONS=--openssl-legacy-provider react-scripts start" - BVB44

24

我刚刚遇到了这个错误,看起来你正在使用 Node 版本 17+。它目前与某些 webpack 技术不兼容。

建议改用 LTS 版本,当前版本为 16.13.0。


4
请注意,昨天 Node 18 成为当前的 LTS 版本。如果您已将依赖项固定在 LTS 标签上,则可能会在下一次构建中出现该问题。请谨慎处理。 - BorysekOndrej
截至2023年2月,Node 18.*和webpack仍然不兼容。如果您想保留Node 18.*的功能,上述的openssl-legacy-provider解决方案可作为一种解决方法。 - Steverino

4

当使用最新的 Node 版本 17.4.0 构建 Docker 镜像时,发生了这个问题。

我通过将其切换到 Node v14 镜像来解决它。


1
如果您正在使用nvm、React Native并遇到此问题,请尝试使用nvm默认版本16.13。
nvm alias default v16.13.0

这帮助我在开发过程中解决了错误。 然后我在创建捆绑包时在发布模式下遇到了错误。 我找出了问题,原来是我使用 nvm 并将 node 17 设置为默认版本。 做完这些之后,

nvm uninstall v17

发布版本中的错误已经消失了。


1
在我的情况下,我有多个版本。我只是卸载了所有的版本(nvm uninstall vxx.xx.x),只留下一个版本v16.13.1。安装其他版本后它就可以工作了。 - user2521166

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接