Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 [BUG] digital envelope routines::unsupported #10824

Closed
epubreader opened this issue Jul 2, 2023 · 6 comments
Closed

🐛 [BUG] digital envelope routines::unsupported #10824

epubreader opened this issue Jul 2, 2023 · 6 comments
Labels

Comments

@epubreader
Copy link

nodejs 版本v16.20.0, 18.0也试过了,也不行

node:internal/crypto/hash:71
this[kHandle] = new _Hash(algorithm, xofLen);
^

Error: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:71:19)
at Object.createHash (node:crypto:130:10)
at BulkUpdateDecorator.hashFactory (/home/mason/project/ecommerce/dashboard/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:184154:18)
at BulkUpdateDecorator.digest (/home/mason/project/ecommerce/dashboard/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:184089:21)
at /home/mason/project/ecommerce/dashboard/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:107234:49
at done (/home/mason/project/ecommerce/dashboard/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:38350:13)
at /home/mason/project/ecommerce/dashboard/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:180888:5
at Hook.eval [as callAsync] (eval at create (/home/mason/project/ecommerce/dashboard/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:50186:10), :6:1)
at AsyncQueue._handleResult (/home/mason/project/ecommerce/dashboard/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:180858:21)
at /home/mason/project/ecommerce/dashboard/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:180841:11
at /home/mason/project/ecommerce/dashboard/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:107076:4
at callback (/home/mason/project/ecommerce/dashboard/node_modules/@umijs/deps/compiled/webpack/5/bundle5.js:34510:20)
at FSReqCallback.oncomplete (node:fs:203:5) {
opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
library: 'digital envelope routines',
reason: 'unsupported',
code

@lovewaner
Copy link

Linux, macOS, Git bash, 输入:
export NODE_OPTIONS=--openssl-legacy-provider

winndows系统输入:
set NODE_OPTIONS=--openssl-legacy-provider

@chenshuai2144
Copy link
Collaborator

TAutomatically replying with ChatGPT can be attempted, but it cannot be guaranteed to be completely accurate and may not fully address all issues. Please feel free to reply if you have any further questions or concerns.
此回复基于 ChatGPT 自动生成,可以尝试下方案,官方人员会在一定时间后继续继续处理。

感谢您提供的错误信息。这个问题似乎是由于标准Node.js加密库与您的环境中的某个openssl版本不兼容引起的。您可以尝试通过设置NODE_OPTIONS环境变量来解决这个问题。

对于Linux、macOS和Git Bash,请在命令行中输入以下命令:

export NODE_OPTIONS=--openssl-legacy-provider

对于Windows系统,请在命令行中输入以下命令:

set NODE_OPTIONS=--openssl-legacy-provider

设置完成后,尝试重新运行您的项目看是否能够解决问题。

如果问题依然存在,您可以尝试以下解决方案:

  1. 确保您的操作系统和Node.js版本是最新的,可以从官方网站下载最新版本的Node.js并安装。

  2. 检查您的openssl版本是否过旧,可以尝试更新openssl版本到最新稳定版。

如果以上方法都无法解决问题,您可以尝试使用其他加密库,如crypto-js。下面是一个使用crypto-js计算SHA256哈希的示例代码:

const SHA256 = require('crypto-js/sha256');

const data = 'Hello, World!';
const hash = SHA256(data).toString();

console.log(hash);

请确保在使用crypto-js之前通过npm install crypto-js命令安装它。

除了以上解决方案,您还可以检查您的代码是否与其他模块或库存在冲突,并确保正确导入和使用React相关的依赖。

希望这些信息能够帮助您解决问题。如果问题仍然存在,请提供更多错误信息或代码示例,以便我们能够提供更准确的解决方案。

@chenshuai2144
Copy link
Collaborator

TAutomatically replying with ChatGPT can be attempted, but it cannot be guaranteed to be completely accurate and may not fully address all issues. Please feel free to reply if you have any further questions or concerns.
此回复基于 ChatGPT 自动生成,可以尝试下方案,官方人员会在一定时间后继续继续处理。

这个错误通常是由于缺少适当的 OpenSSL 版本导致的。你可以尝试以下解决方案来解决这个问题:

  1. 确认 OpenSSL 版本:首先,确保你的系统上安装了 OpenSSl,并且版本是兼容的。你可以在终端中运行以下命令来检查 OpenSSL 版本:

    openssl version
    

    确保版本是 1.1.1 或更高版本。如果你的版本较低,建议更新 OpenSSL。

  2. 升级 Node.js:尝试升级 Node.js 到最新版本。你提到已经尝试过 v16.20.0 和 18.0,但仍然遇到问题。可以尝试使用 Node.js 官方提供的其他版本管理工具(如 nvm)来安装和管理 Node.js 版本。

  3. 清除模块缓存:有时候,由于模块缓存的问题,可能会导致报错。你可以尝试清除项目的模块缓存,并重新安装依赖。在项目根目录下运行以下命令:

    rm -rf node_modules
    npm cache clean --force
    npm install
  4. 确保依赖项兼容性:如果你的项目中使用了一些依赖库,特别是涉及加密和安全的库,确保它们与你正在使用的 Node.js 和 OpenSSL 版本相兼容。检查并确保所有依赖项都是最新的,并且没有已知的不兼容性问题。

如果以上解决方案都无法解决问题,可能需要进一步检查你的代码和环境配置。如果你可以提供更多关于你的项目配置、代码片段或其他相关的错误信息,我可以帮助你给出更具体的解决方案。

@swsoyee
Copy link

swsoyee commented Dec 6, 2023

@chenshuai2144 我在运行打包命令时出现了该问题。

首先我在运行 npm start 的时候也出现了这个问题,在我修改启动命令后能正常启动,问题似乎得到了解决。

-    "start": "cross-env UMI_ENV=dev umi dev",
+    "start": "cross-env NODE_OPTIONS=--openssl-legacy-provider UMI_ENV=dev umi dev",

但该问题在运行 npm run build 的时候再次出现

npm run build

> ant-design-pro@5.2.0 build
> umi build

Browserslist: caniuse-lite is outdated. Please run:
  npx update-browserslist-db@latest
  Why you should do it regularly: https://github.com/browserslist/update-db#readme
Bundle with webpack 5...

* Webpack █████████████████████████ building (10%) 0/1 entries 0/0 dependencies 0/0 modules 0 active


(node:2004) [DEP_WEBPACK_CONFIGURATION_OPTIMIZATION_NO_EMIT_ON_ERRORS] DeprecationWarning: optimization.noEmitOnErrors is deprecated in favor of optimization.emitOnErrors
(Use `node --trace-deprecation ...` to show where the warning was created)
(node:2004) [DEP_WEBPACK_COMPILATION_OPTIMIZE_CHUNK_ASSETS] DeprecationWarning: optimizeChunkAssets is deprecated (use Compilation.hooks.processAssets instead and use one of Compilation.PROCESS_ASSETS_STAGE_* as stage option)
(node:2004) [DEP_WEBPACK_COMPILATION_NORMAL_MODULE_LOADER_HOOK] DeprecationWarning: Compilation.hooks.normalModuleLoader was moved to NormalModule.getCompilationHooks(compilation).loader
node:internal/crypto/hash:68
  this[kHandle] = new _Hash(algorithm, xofLen);
                  ^

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:68:19)
    at Object.createHash (node:crypto:138:10)
    at BulkUpdateDecorator.hashFactory (C:\Users\**\local-project\node_modules\@umijs\deps\compiled\webpack\5\bundle5.js:184161:18)
    at BulkUpdateDecorator.update (C:\Users\**\local-project\node_modules\@umijs\deps\compiled\webpack\5\bundle5.js:184062:50)
    at C:\Users\**\local-project\node_modules\@umijs\deps\compiled\webpack\5\bundle5.js:107101:9
    at processTicksAndRejections (node:internal/process/task_queues:82:21)
    at runNextTicks (node:internal/process/task_queues:64:3)
    at processImmediate (node:internal/timers:449:9) {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

Node.js v21.2.0

系统信息如下

PS C:\Users\**\local-project\> node -v
v21.2.0
PS C:\Users\**\local-project\> openssl version
OpenSSL 3.2.0 23 Nov 2023 (Library: OpenSSL 3.2.0 23 Nov 2023)

- Microsoft Windows 11 Pro
- 10.0.22621 N/A build 22621

尝试过 #10824 (comment) #10824 (comment) 的办法都无法解决。更换使用 crypto-js 的办法没有尝试过,因为我的项目中尚不需要用到 crypto,目前仍然是基于原始的模板( https://pro.ant.design/zh-CN/docs/getting-started )上稍作修改,没有引入过新的 package。

@chenshuai2144
Copy link
Collaborator

build 的时候也加下环境变量

@swsoyee
Copy link

swsoyee commented Dec 7, 2023

@chenshuai2144 谢谢提醒。按下述方法可以解决

-    "build": "umi build",
+    "build": "cross-env NODE_OPTIONS=--openssl-legacy-provider umi build",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants