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


当前回答

“快速修复”的建议对我很有效。cd到你新建的App目录;您可能需要sudo这个安装,然后运行以下:

运行: NPM install -g NPM -check-updates

然后: 中央大学- u

然后: npm安装

然后: npm开始

其他回答

我也犯了同样的错误。

我的情况:

安装了新的react typescript应用程序,添加了一些scss和一些组件。

在本地我的构建是工作的,但当我试图发布它失败与错误:

Error: error:0308010C:digital envelope routines::unsupported

我通过将react-script库更新到5.0.1来修复这个问题

"react-scripts": "^5.0.1",

这个答案是一个立即的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版本17+,所以尝试降级Node.js版本。

从计算机上卸载Node.js。 从https://nodejs.org/download/release/v16.13.0/下载Node.js版本16并重新安装

这是所有。

如果遇到此错误,并且不想更改主配置,则可以使用以下方法进行简单的修复。不过,我不确定这是否被推荐为一种好的做法。

请随意改正。

最初,假设这是我的包的脚本部分。json文件:

...
"version": "1.0.0",
  "scripts": {
    ...
    "build": "npm run build:test-app:testing",
    "build:test-app:testing": "ng build test-app --deploy-url  https://test-app.com/ --configuration=test-config",
    ...
  },
  "private": true,
...

为了使用这个导出NODE_OPTIONS=——openssl-legacy-provider,您可以执行以下操作:

"version": "1.0.0",
  "scripts": {
....
    "build": "NODE_OPTIONS=--openssl-legacy-provider npm run build:test-app:testing”,
    "build:test-app:testing": "NODE_OPTIONS=--openssl-legacy-provider ng build test-app --deploy-url  https://test-app.com/ --configuration=test-config"
...
  },
  "private": true,

注意构建脚本。我添加了一个选项:NODE_OPTIONS=——openssl-legacy-provider

这有助于在Node.js version 17中解决此错误。

对于那些可以灵活更改构建系统的Node.js版本的人,只需切换到低于17的版本,例如,版本16。

对于Docker,最初使用this的用例,它总是提取最新版本:

...
FROM node:alpine
...

你可以切换到如下内容:

...
FROM node:16-alpine3.12
...

我通过使用LTS版本修复:

echo "lts" > .nvmrc
nvm install

React Native有一个有bug的脚本来查找Node.js可执行文件的路径。

这将通过节点版本管理器将版本设置为Node.js的最新稳定版本。

我发现即使Node.js在我的路径中,如果我有一个~/。它将尝试在NVM中找到用途,但失败了。这将当前节点设置为链接到~/中的节点。nvm,因此React Native可以找到。