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


当前回答

当我用nvm更改节点版本时,我也遇到了同样的问题。如果Ypu在你的项目中使用sass,请尝试:

Sudo NPM重建node-sass

其他回答

在Dockerfile上,你应该添加:

ENV NODE_OPTIONS=--openssl-legacy-provider

我也犯了同样的错误。

我的情况:

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

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

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

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

"react-scripts": "^5.0.1",

对于Angular应用:

你也可以在package.json中编辑npm启动脚本。而不是

"start": "ng serve -o"

to

"start": "set NODE_OPTIONS=--openssl-legacy-provider && ng serve -o"

当你在终端/命令行中运行npm run start时,它会首先设置NODE_OPTIONS来避免这个问题。

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

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

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

"start": "react-scripts start"

to

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