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


当前回答

在使用VueJS时遇到了这个问题。

使用-openssl-legacy-provider的一个缺点是旧版本的Node不支持它。当提供此标志时,旧版本的Node根本不运行。 但我仍然希望与Node v16及更早版本兼容。

VueJS使用md4算法来生成散列(实际上它是WebPack的底层)。出于这些目的,md5可以很容易地取代Md4。所使用的算法类型,在大多数地方都是硬编码的,所以没有办法配置另一种算法。

所以我想出了另一个变通办法。从crypto模块拦截原始createHash()调用并将其替换为修改后的版本的函数。这是vue.config.js文件的开头:

const crypto = require('crypto');

/**
 * md4 algorithm is not available anymore in NodeJS 17+ (because of lib SSL 3).
 * In that case, silently replace md4 by md5 algorithm.
 */
try {
  crypto.createHash('md4');
} catch (e) {
  console.warn('Crypto "md4" is not supported anymore by this Node version');
  const origCreateHash = crypto.createHash;
  crypto.createHash = (alg, opts) => {
    return origCreateHash(alg === 'md4' ? 'md5' : alg, opts);
  };
}

其他回答

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

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

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

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

它是Node.js版本。

我在Node.js 17上有这个错误,但当我使用nvm将我的Node.js版本切换到旧版本(16)时,它是好的。

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

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

构造变压器失败:错误:错误:0308010C:数字信封例程::不支持

解决上述错误的最简单和最简单的解决方案是将Node.js降级到v14.18.1。然后只需删除文件夹node_modules,并尝试重新构建项目,您的错误必须解决。