我正在上一门课程React项目并使用React开发服务器。
在安装MongoDB本地社区服务器之前,我一直可以运行 npm start ,不确定该项目是否相关,因为我没有在项目中包含任何MongoDB。我在过去2个小时里做了一些Google,发现了答案和建议参差不齐。我尝试卸载MongoDB并删除其PATH变量,但仍然无法解决问题。
任何建议将不胜感激。
这是我收到的Npm错误消息:
Starting the development server...
events.js:292
throw er; // Unhandled 'error' event
^
Error: spawn cmd ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
at onErrorNT (internal/child_process.js:469:16)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
Emitted 'error' event on ChildProcess instance at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:273:12)
at onErrorNT (internal/child_process.js:469:16)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
errno: 'ENOENT',
code: 'ENOENT',
syscall: 'spawn cmd',
path: 'cmd',
spawnargs: [ '/s', '/c', 'start', '""', '/b', '"http://localhost:3000/"' ]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! burger-app@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the burger-app@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Roy\AppData\Roaming\npm-cache\_logs\2020-08-27T08_59_44_741Z-debug.log
这是日志输出:
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'start'
1 verbose cli ]
2 info using npm@6.14.6
3 info using node@v12.18.3
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle burger-app@0.1.0~prestart: burger-app@0.1.0
6 info lifecycle burger-app@0.1.0~start: burger-app@0.1.0
7 verbose lifecycle burger-app@0.1.0~start: unsafe-perm in lifecycle true
8 verbose lifecycle burger-app@0.1.0~start: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;c:\Code\React\Course\burger-app\node_modules\.bin;C:\Program Files\nodejs\;C:\Users\Roy\AppData\Local\Microsoft\WindowsApps;C:\Users\Roy\AppData\Local\Programs\Microsoft VS Code\bin;C:\Program Files\MongoDB\Server\4.4\bin;C:\Users\Roy\AppData\Roaming\npm
9 verbose lifecycle burger-app@0.1.0~start: CWD: c:\Code\React\Course\burger-app
10 silly lifecycle burger-app@0.1.0~start: Args: [ '/d /s /c', 'react-scripts start' ]
11 silly lifecycle burger-app@0.1.0~start: Returned: code: 1 signal: null
12 info lifecycle burger-app@0.1.0~start: Failed to exec start script
13 verbose stack Error: burger-app@0.1.0 start: `react-scripts start`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack at EventEmitter.emit (events.js:315:20)
13 verbose stack at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:315:20)
13 verbose stack at maybeClose (internal/child_process.js:1021:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
14 verbose pkgid burger-app@0.1.0
15 verbose cwd c:\Code\React\Course\burger-app
16 verbose Windows_NT 10.0.19041
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
18 verbose node v12.18.3
19 verbose npm v6.14.6
20 error code ELIFECYCLE
21 error errno 1
22 error burger-app@0.1.0 start: `react-scripts start`
22 error Exit status 1
23 error Failed at the burger-app@0.1.0 start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
这是我项目的package.json文件:
{
"name": "burger-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.5.0",
"@testing-library/user-event": "^7.2.1",
"axios": "^0.19.2",
"prop-types": "^15.7.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
这是我系统的PATH变量:
答案 0 :(得分:0)
经过数次谷歌搜索和阅读之后,这实际上解决了该问题:
问题是由于某种原因,%systemRoot%变量已从Windows系统变量PATH变量中删除。
仅在将这些变量手动添加回系统的PATH变量后,问题才得以解决:
%SystemRoot%\system32
%SystemRoot%
%SystemRoot%\System32\Wbem
%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\
%SYSTEMROOT%\System32\OpenSSH\