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


当前回答

我也犯了同样的错误。

我的情况:

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

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

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

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

"react-scripts": "^5.0.1",

其他回答

我在GitHub上找到了以下命令:

对于Windows,在cmd中使用以下命令:

set NODE_OPTIONS=--openssl-legacy-provider

对于Unix,使用:

export NODE_OPTIONS=--openssl-legacy-provider

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

请随意改正。

最初,假设这是我的包的脚本部分。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
...

我也犯了同样的错误。

我的情况:

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

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

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

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

"react-scripts": "^5.0.1",

在你的包裹里。Json:更改这一行

"start": "react-scripts start"

to

"start": "react-scripts --openssl-legacy-provider start"

这个解决方案对我很有效。

这个错误出现在Node.js版本17+,所以尝试降级Node.js版本。

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

这是所有。