2024/12/06 20:35
报错原因
这个错误是由于 Node.js 版本与项目的兼容性问题导致的。你遇到的是 OpenSSL 相关的错误,这在较新版本的 Node.js 中比较常见。
解决方案
```plaintext
方案1 - 设置环境变量(推荐):在 Windows 命令行中运行以下命令:
set SET NODE_OPTIONS=--openssl-legacy-provider
然后重新运行:
npm start方案2 - 降级 Node.js:
1. 卸载当前的 Node.js v22.11.0
2. 安装 Node.js v16.x LTS 版本
3. 重新运行 npm install && npm start方案3 - 修改 package.json:
将 scripts 部分的 start 命令修改为:
{
"scripts": {
"start": "set SET NODE_OPTIONS=--openssl-legacy-provider && react-scripts start"
}
}
```
建议使用方案1,因为这是最简单且不需要修改项目文件的方法。
如果还是不行,可以尝试:
1. 清除 node_modules:`rm -rf node_modules`
2. 清除 package-lock.json:`rm package-lock.json`
3. 重新安装:`npm install`
4. 设置环境变量:`set SET NODE_OPTIONS=--openssl-legacy-provider`
5. 启动项目:`npm start`
这个问题主要是因为你使用的 Node.js v22.11.0 版本太新,而项目可能使用了一些较旧的依赖包。
Successful operation
详细报错
Microsoft Windows [版本 10.0.22000.2538]
(c) Microsoft Corporation。保留所有权利。
E:\React\react-bilibli-ToDoList>cd..
E:\React>cd weatherApp-Reactjs-master
E:\React\weatherApp-Reactjs-master>npm i && npm start
npm warn cleanup Failed to remove some directories [
npm warn cleanup [
npm warn cleanup 'E:\\React\\weatherApp-Reactjs-master\\node_modules\\watchpack-chokidar2',
npm warn cleanup [Error: EPERM: operation not permitted, rmdir 'E:\React\weatherApp-Reactjs-master\node_modules\watchpack-chokidar2\node_modules\string_decoder'] {
npm warn cleanup errno: -4048,
npm warn cleanup code: 'EPERM',
npm warn cleanup syscall: 'rmdir',
npm warn cleanup path: 'E:\\React\\weatherApp-Reactjs-master\\node_modules\\watchpack-chokidar2\\node_modules\\string_decoder'
npm warn cleanup }
npm warn cleanup ]
npm warn cleanup ]
Starting the development server...
Error: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:79:19)
at Object.createHash (node:crypto:139:10)
at module.exports (E:\React\weatherApp-Reactjs-master\node_modules\webpack\lib\util\createHash.js:135:53)
at NormalModule._initBuildHash (E:\React\weatherApp-Reactjs-master\node_modules\webpack\lib\NormalModule.js:417:16)
at handleParseError (E:\React\weatherApp-Reactjs-master\node_modules\webpack\lib\NormalModule.js:471:10)
at E:\React\weatherApp-Reactjs-master\node_modules\webpack\lib\NormalModule.js:503:5
at E:\React\weatherApp-Reactjs-master\node_modules\webpack\lib\NormalModule.js:358:12
at E:\React\weatherApp-Reactjs-master\node_modules\loader-runner\lib\LoaderRunner.js:373:3
at iterateNormalLoaders (E:\React\weatherApp-Reactjs-master\node_modules\loader-runner\lib\LoaderRunner.js:214:10)
at iterateNormalLoaders (E:\React\weatherApp-Reactjs-master\node_modules\loader-runner\lib\LoaderRunner.js:221:10)
E:\React\weatherApp-Reactjs-master\node_modules\react-scripts\scripts\start.js:19
throw err;
^
Error: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:79:19)
at Object.createHash (node:crypto:139:10)
at module.exports (E:\React\weatherApp-Reactjs-master\node_modules\webpack\lib\util\createHash.js:135:53)
at NormalModule._initBuildHash (E:\React\weatherApp-Reactjs-master\node_modules\webpack\lib\NormalModule.js:417:16)
at E:\React\weatherApp-Reactjs-master\node_modules\webpack\lib\NormalModule.js:452:10
at E:\React\weatherApp-Reactjs-master\node_modules\webpack\lib\NormalModule.js:323:13
at E:\React\weatherApp-Reactjs-master\node_modules\loader-runner\lib\LoaderRunner.js:367:11
at E:\React\weatherApp-Reactjs-master\node_modules\loader-runner\lib\LoaderRunner.js:233:18
at context.callback (E:\React\weatherApp-Reactjs-master\node_modules\loader-runner\lib\LoaderRunner.js:111:13)
at E:\React\weatherApp-Reactjs-master\node_modules\babel-loader\lib\index.js:59:103 {
opensslErrorStack: [
'error:03000086:digital envelope routines::initialization error',
'error:0308010C:digital envelope routines::unsupported'
],
library: 'digital envelope routines',
reason: 'unsupported',
code: 'ERR_OSSL_EVP_UNSUPPORTED'
}
Node.js v22.11.0
E:\React\weatherApp-Reactjs-master>