我是react-js的初学者,我正在尝试在reactjs中运行我的第一个应用程序,但是npm start出现错误,请帮助我如何启动npm。
node js版本
v12.1.0
npm版本
npm -v 6.9.0
运行npm时出现错误
C:\Users\NanduCn\first-project>npm start
> first-project@0.1.0 start C:\Users\NanduCn\first-project
> node server.js
internal/modules/cjs/loader.js:613
throw err;
^
Error: Cannot find module 'C:\Users\NanduCn\first-project\server.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:610:15)
at Function.Module._load (internal/modules/cjs/loader.js:526:27)
at Function.Module.runMain (internal/modules/cjs/loader.js:824:10)
at internal/main/run_main_module.js:17:11
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! first-project@0.1.0 start: `node server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the first-project@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\NanduCn\AppData\Roaming\npm-cache\_logs\2019-04-30T10_38_04_898Z-debug.log
这是我的应用程序package.json文件:
{
"name": "first-project",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.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"
]
}
}
我正在更改以启动反应脚本,它又出现另一个错误:
Starting the development server...
events.js:173
throw er; // Unhandled 'error' event
^
Error: spawn cmd ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:248:19)
at onErrorNT (internal/child_process.js:431:16)
at processTicksAndRejections (internal/process/task_queues.js:84:17)
Emitted 'error' event at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:254:12)
at onErrorNT (internal/child_process.js:431:16)
at processTicksAndRejections (internal/process/task_queues.js:84:17)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! first-project@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the first-project@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\NanduCn\AppData\Roaming\npm-cache\_logs\2019-04-30T11_26_54_037Z-debug.log
答案 0 :(得分:0)
如果它是您的react应用程序,则通过以下方式更改package.json中的开始
"start": "react-scripts start"
不是
"start": "node server.js"
答案 1 :(得分:0)
使用
“ start”:“ react-scripts start”,但请确保您在根目录上具有server.js。 react-scripts start将在根目录中查找server.js。