首页 > 解决方案 > 尝试 npx idk 部署 React 应用程序时出现 ERR_OSSL_EVP_UNSUPPORTED

问题描述

我发布这篇文章是为了希望能让其他人摆脱我遇到的一些令人头疼的桌面时刻。

今天尝试运行 npx cdk deploy 时收到以下错误:

[my user]@MacBook-Pro: ~/[Path-to-my-project] $ npx cdk deploy [12:19:19] Bundling asset ApplicationStack/WebApp/WebAppDeploy/WebAppDeploy/Asset1/Stage... yarn run v1.22.15 warning Skipping preferred cache folder "/.cache/yarn" because it is not writable. warning Selected the next writable cache folder in the list, will be "/tmp/.yarn-cache-501". $ react-scripts build warning Cannot find a suitable global folder. Tried these: "/usr/local, /.yarn" Creating an optimized production build... Error: error:0308010C:digital envelope routines::unsupported at new Hash (node:internal/crypto/hash:67:19) at Object.createHash (node:crypto:130:10) at module.exports (/asset-input/node_modules/webpack/lib/util/createHash.js:135:53) at NormalModule._initBuildHash (/asset-input/node_modules/webpack/lib/NormalModule.js:417:16) at handleParseError (/asset-input/node_modules/webpack/lib/NormalModule.js:471:10) at /asset-input/node_modules/webpack/lib/NormalModule.js:503:5 at /asset-input/node_modules/webpack/lib/NormalModule.js:358:12 at /asset-input/node_modules/loader-runner/lib/LoaderRunner.js:373:3 at iterateNormalLoaders (/asset-input/node_modules/loader-runner/lib/LoaderRunner.js:214:10) at iterateNormalLoaders (/asset-input/node_modules/loader-runner/lib/LoaderRunner.js:221:10) at /asset-input/node_modules/loader-runner/lib/LoaderRunner.js:236:3 at runSyncOrAsync (/asset-input/node_modules/loader-runner/lib/LoaderRunner.js:130:11) at iterateNormalLoaders (/asset-input/node_modules/loader-runner/lib/LoaderRunner.js:232:2) at Array.<anonymous> (/asset-input/node_modules/loader-runner/lib/LoaderRunner.js:205:4) at Storage.finished (/asset-input/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:55:16) at /asset-input/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:91:9 /asset-input/node_modules/react-scripts/scripts/build.js:19 throw err; ^ Error: error:0308010C:digital envelope routines::unsupported at new Hash (node:internal/crypto/hash:67:19) at Object.createHash (node:crypto:130:10) at module.exports (/asset-input/node_modules/webpack/lib/util/createHash.js:135:53) at NormalModule._initBuildHash (/asset-input/node_modules/webpack/lib/NormalModule.js:417:16) at /asset-input/node_modules/webpack/lib/NormalModule.js:452:10 at /asset-input/node_modules/webpack/lib/NormalModule.js:323:13 at /asset-input/node_modules/loader-runner/lib/LoaderRunner.js:367:11 at /asset-input/node_modules/loader-runner/lib/LoaderRunner.js:233:18 at context.callback (/asset-input/node_modules/loader-runner/lib/LoaderRunner.js:111:13) at /asset-input/node_modules/react-scripts/node_modules/babel-loader/lib/index.js:59:103 { opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ], library: 'digital envelope routines', reason: 'unsupported', code: 'ERR_OSSL_EVP_UNSUPPORTED' } Node.js v17.0.1 error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. Failed to bundle asset ApplicationStack/WebApp/WebAppDeploy/WebAppDeploy/Asset1/Stage, bundle output is located at /Users/[my user]/PycharmProjects/ps-serverless-app/infrastructure/cdk.out/asset.8c7ae86f7dabf723a79310f22f328c471bdaec37da5325cd834784dc03a40eff-error: Error: docker exited with status 1 Subprocess exited with error 1 FAIL

这个错误有点令人困惑,因为我的节点版本是 v16.13.0 似乎只需将 npm 升级到 v8.1.3 就足以触发这个问题。

这似乎与尝试使用 MD4 算法有关。

我在这里找到了一篇文章,该文章针对我的具体情况提供了有效的解决方案。Chesiremoe 的回答对我来说非常有效。

不幸的是,我在这里没有足够的“街头信誉”来评论该帖子并特别感谢该用户,但非常感谢这个答案!

将此代码添加到 node_modules\react-scripts\config\webpack.config.js 解决了这个问题:

const crypto = require("crypto"); const crypto_orig_createHash = crypto.createHash; crypto.createHash = algorithm => crypto_orig_createHash(algorithm == "md4" ? "sha256" : algorithm);

标签: node.jsnpmwebpackaws-cdk

解决方案


推荐阅读