我正在尝试使用 NPX create React app 创建一个 React 应用程序,并且 npm install 运行正常,但应该运行代码的 npm start 会出现错误。
这是错误
> react-scripts start
i 「wds」: Project is running at http://10.54.83.144/
i 「wds」: webpack output is served from
i 「wds」: Content not from webpack is served from C:\Users\xyz\Desktop\app\my-app\public
i 「wds」: 404s will fallback to /
Starting the development server...
events.js:288
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! <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="016c782c60717141312f302f31" rel="noreferrer noopener nofollow">[email protected]</a> start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7e1307531f0e0e3e4e504f504e" rel="noreferrer noopener nofollow">[email protected]</a> 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\xyz\AppData\Roaming\npm-cache\_logs\2020-03-09T20_33_16_720Z-debug.log
这是package.json
{
"name": "my-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",
"react": "^16.13.0",
"react-dom": "^16.13.0",
"react-scripts": "^3.4.0"
},
"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"
]
}
}
这是完整的调试日志文件。
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:\\Users\\xyz\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'start'
1 verbose cli ]
2 info using <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2a445a476a1c041b1e0418" rel="noreferrer noopener nofollow">[email protected]</a>
3 info using <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9df3f2f9f8ddebacafb3acabb3ac" rel="noreferrer noopener nofollow">[email protected]</a>
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c1acb8eca0b1b181f1eff0eff1" rel="noreferrer noopener nofollow">[email protected]</a>~prestart: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="adc0d480ccdddded9d839c839d" rel="noreferrer noopener nofollow">[email protected]</a>
6 info lifecycle <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bad7c397dbcacafa8a948b948a" rel="noreferrer noopener nofollow">[email protected]</a>~start: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b6dbcf9bd7c6c6f68698879886" rel="noreferrer noopener nofollow">[email protected]</a>
7 verbose lifecycle <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1c7165317d6c6c5c2c322d322c" rel="noreferrer noopener nofollow">[email protected]</a>~start: unsafe-perm in lifecycle true
8 verbose lifecycle <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8ee3f7a3effefecebea0bfa0be" rel="noreferrer noopener nofollow">[email protected]</a>~start: PATH: C:\Users\xyz\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\xyz\Desktop\app\my-app\node_modules\.bin;C:\Program Files (x86)\RSA SecurID Token Common;C:\Program Files\RSA SecurID Token Common;C:\apache\maven3.6.1\bin;C:\Program Files\Java\jdk1.8.0_241\bin;C:\Program Files\nodejs\;C:\Users\xyz\AppData\Local\Microsoft\WindowsApps;;C:\Users\xyz\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\xyz\AppData\Roaming\npm
9 verbose lifecycle <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a6cbdf8bc7d6d6e69688978896" rel="noreferrer noopener nofollow">[email protected]</a>~start: CWD: C:\Users\xyz\Desktop\app\my-app
10 silly lifecycle <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="78150155190808384856495648" rel="noreferrer noopener nofollow">[email protected]</a>~start: Args: [ '/d /s /c', 'react-scripts start' ]
11 silly lifecycle <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="234e5a0e42535363130d120d13" rel="noreferrer noopener nofollow">[email protected]</a>~start: Returned: code: 1 signal: null
12 info lifecycle <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8ae7f3a7ebfafacabaa4bba4ba" rel="noreferrer noopener nofollow">[email protected]</a>~start: Failed to exec start script
13 verbose stack Error: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f89581d5998888b8c8d6c9d6c8" rel="noreferrer noopener nofollow">[email protected]</a> start: `react-scripts start`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (C:\Users\xyz\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack at EventEmitter.emit (events.js:311:20)
13 verbose stack at ChildProcess.<anonymous> (C:\Users\xyz\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:311: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 <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a7cade8ac6d7d7e79789968997" rel="noreferrer noopener nofollow">[email protected]</a>
15 verbose cwd C:\Users\xyz\Desktop\app\my-app
16 verbose Windows_NT 10.0.17763
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\xyz\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "start"
18 verbose node v12.16.1
19 verbose npm v6.14.2
20 error code ELIFECYCLE
21 error errno 1
22 error <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2c4155014d5c5c6c1c021d021c" rel="noreferrer noopener nofollow">[email protected]</a> start: `react-scripts start`
22 error Exit status 1
23 error Failed at the <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c6abbfeba7b6b686f6e8f7e8f6" rel="noreferrer noopener nofollow">[email protected]</a> start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
我尝试删除节点模块并删除缓存,然后再次使用 NPM INSTALL
但它们不起作用。我在这里缺少什么?
最佳答案
解决方案1
将环境变量设置为 C:\Windows\System32。
解决方案2
如果第一个步骤不起作用,请按照第二个步骤操作。导航到您的项目文件夹并输入此命令>>>
rm -rf node_modules
rm package-lock.json
rm yarn.lock
npm cache clear --force
npm install
解决方案3
降级package.json文件中的react-scripts
关于reactjs - npm 开始报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60608201/