我创建了默认的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天前遇到了这个问题,目前仍在处理。


当前回答

与节点v18.0.0版本相同的错误 和nuxt框架版本2.15时运行的开发服务器,将修复:

"scripts": {
  "dev": "NODE_OPTIONS=--openssl-legacy-provider nuxt"
}

其他回答

Try:

npm create react-app --template typescript foo --use-npm

听起来很简单,如果可行的话,升级包中的所有依赖项。json到最新的(只要在npm中输入名称并使用建议的版本),也使用node的最新LTS版本。

我以前遇到过问题,即使将我的项目迁移到使用yarn,我也能够最终解决这个问题,不需要用ssl黑客来妥协安全性

在角。io项目,node .js的接受(不支持)版本是v16.x.x。

在Nodes v17中。X版本,同样的错误发生在这个问题中描述。

解决方案:

卸载节点,重新安装v16版本。x (Windows)。

这个答案是一个立即的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“正式”降级为过时。

有很多变通办法(主要是降级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链接可以查看其他可用的哈希算法。