【发布时间】:2020-11-08 01:03:03
【问题描述】:
当我运行npm start 命令为我的第一个 React 项目启动服务器时,出现如下错误。我尝试卸载并重新安装 node.js,但没有成功。我该如何解决这个问题?我在这里包括我的package.json 和我的目录结构。
这是错误:
> reactproject1@1.0.0 start C:\Users\LENOVO\reactproject1
> node index.js
internal/modules/cjs/loader.js:969
throw err;
^
Error: Cannot find module 'C:\Users\LENOVO\reactproject1\index.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:966:15)
at Function.Module._load (internal/modules/cjs/loader.js:842:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! reactproject1@1.0.0 start: `node index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the reactproject1@1.0.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\LENOVO\AppData\Roaming\npm-cache\_logs\2020-07-18T09_12_04_972Z-debug.log
这是我的 react 项目的 package.json 文件。我已通过添加"start":"node index.js" 对其进行了编辑。
{
"name": "reactproject1",
"version": "1.0.0",
"description": "restropart",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"react": "^16.13.1",
"react-dom": "^16.13.1"
}
}
我的目录树如下
-ReactProject
-node_modules
-public
-src
->index.js
-package.json
-package-lock.json
我的index.js 文件位于src 文件夹中。 node_modules、public、src、package.json 和 package-lock.json 文件位于同一行。
【问题讨论】:
-
你的项目根目录中有
index.js文件吗? -
能否展示一下你的项目文件结构以及 index.js 文件在哪里
-
我在问题中添加了我的项目文件结构。请通过它。 @穆雷尼克。感谢您的回复。
-
@ShauryaVardhanSingh 很高兴收到您的回复。我在我的问题区域中添加了结构。请帮助解决错误!
标签: node.js reactjs npm npm-start