【问题标题】:Getting error 'digital envelope routines', reason: 'unsupported', code: 'ERR_OSSL_EVP_UNSUPPORTED' [duplicate]收到错误“数字信封例程”,原因:“不支持”,代码:“ERR_OSSL_EVP_UNSUPPORTED”
【发布时间】:2021-12-11 14:52:53
【问题描述】:

我在学习 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"
  }
}

【问题讨论】:

标签: node.js reactjs next.js


【解决方案1】:

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

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

  2. 在 package.json 中添加 NODE_OPTIONS=--openssl-legacy-provider

    "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 找不到或输入错误的错误。
  • 在 Linux 上为我工作。为方便起见,将导出添加到我的 .bashrc。
【解决方案2】:

我刚刚收到此错误,看来您使用的是 Node 版本 17+。它还不兼容一些 webpack 的东西。

尝试改用 LTS 版本,目前为 16.13.0。

【讨论】:

    猜你喜欢
    • 2021-12-08
    • 2021-12-10
    • 2023-03-12
    • 2022-01-02
    • 2021-12-31
    • 2022-06-22
    • 1970-01-01
    • 2022-09-30
    相关资源
    最近更新 更多