我创建了默认的IntelliJ IDEA React项目,并得到了这个:

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 (/Users/user/Programming Documents/WebServer/untitled/node_modules/webpack/lib/util/createHash.js:135:53)
    at NormalModule._initBuildHash (/Users/user/Programming Documents/WebServer/untitled/node_modules/webpack/lib/NormalModule.js:417:16)
    at handleParseError (/Users/user/Programming Documents/WebServer/untitled/node_modules/webpack/lib/NormalModule.js:471:10)
    at /Users/user/Programming Documents/WebServer/untitled/node_modules/webpack/lib/NormalModule.js:503:5
    at /Users/user/Programming Documents/WebServer/untitled/node_modules/webpack/lib/NormalModule.js:358:12
    at /Users/user/Programming Documents/WebServer/untitled/node_modules/loader-runner/lib/LoaderRunner.js:373:3
    at iterateNormalLoaders (/Users/user/Programming Documents/WebServer/untitled/node_modules/loader-runner/lib/LoaderRunner.js:214:10)
    at iterateNormalLoaders (/Users/user/Programming Documents/WebServer/untitled/node_modules/loader-runner/lib/LoaderRunner.js:221:10)
/Users/user/Programming Documents/WebServer/untitled/node_modules/react-scripts/scripts/start.js:19
  throw err;
  ^

这似乎是最近才出现的问题——webpack在4天前遇到了这个问题,目前仍在处理。


当前回答

作为一个2022年的读者,没有一个答案说明这个问题在Webpack 5用户的早期被修复了(但没有反向移植到Webpack 4)。如果你是Webpack 5,只需升级到至少5.61.0。请参阅此处关于跟踪此问题的线程的评论。

其他回答

有很多变通办法(主要是降级Node.js, OpenSSL,或允许不安全的散列),但潜在的问题是Webpack的输出。hashFunction默认为md4,这会在最新版本的OpenSSL中触发此错误。

从Webpack的输出。hashFunction文档:

从Webpack v5.54.0+开始,hashFunction支持xxhash64作为一种更快的算法,当 实验。futureDefaults已启用。

解决方案是:

设置输出。hashFunction = 'xxhash64' 设置实验。futureDefaults = true

在Webpack配置中。

如果您使用的是较旧版本的Webpack(在v5.54.0之前),请遵循输出。hashFunction链接可以查看其他可用的哈希算法。

这个答案是一个立即的OpenSSL系统级解决方案,而不涉及以前工作的构建配置。

在理想的情况下,你有时间升级和迁移不安全的构建依赖项,并确保你没有破坏应用程序中的其他东西(或者完全避免webpack,或者在我的例子中从vue-cli迁移到使用esbuild的vite)。

相反,你“应该”(a)告诉webpack使用一个更新的哈希函数,或者(b)用npm审计减轻违规包。


系统级OpenSSL解决方案

最快的解决方法是通过在系统范围的OpenSSL配置中启用“遗留的”加密提供者来临时重新启用MD4。

这是非常不安全和笨拙的。然后,您应该禁用遗留的加密方法。

(不幸的是,下面的测试只适用于Linux)。

Backup your existing OpenSSL configuration: sudo cp /etc/ssl/openssl.cnf /etc/ssl/openssl.cnf.BAK Append (or uncomment) the following configuration to enable the legacy "providers" (as OpenSSL calls them). You probably want to sudo vim /etc/ssl/openssl.cnf or similar. [provider_sect] default = default_sect legacy = legacy_sect [default_sect] activate = 1 [legacy_sect] activate = 1 Rerun your node script as before. Disable the legacy providers afterwards. sudo mv -f /etc/ssl/openssl.cnf.BAK /etc/ssl/openssl.cnf

这个解决方案来自于一个类似问题的答案。


深层原因是什么?

Node在*nix系统上使用OpenSSL作为哈希函数和加密。最新版本的OpenSSL默认禁用MD4——这将破坏任何以前使用MD4的工作程序。考虑到这一点,任何认为使用MD4进行文件哈希是一个“好主意”的npm包现在都被破坏了——即使MD4自1996年以来就被RSA实验室认为是破坏的!MD4也在2011年被RFC 6150“正式”降级为过时。

echo 'export NODE_OPTIONS=——openssl-legacy-provider' >> ~/。ZSHRC为我工作

当我试图运行我新克隆的网站时,我就遇到了这个问题:

npm install

访问::https://nodejs.org/en/

并下载大多数用户的推荐版本。

然后卸载PC上的Node.js,重新安装推荐版本。

据我所知,这是开发团队的问题。他们会尽快修复,但在此期间使用推荐版本,一切都会好起来的。