[英]Node.js Cannot Find Module error on npm start
I am getting an error like the below when I run npm start
command to start the server for my first react project.当我运行npm start
命令为我的第一个反应项目启动服务器时,出现如下错误。 I have tried uninstalling and reinstalling the node.js but did not work.我试过卸载并重新安装 node.js 但没有用。 How can I resolve this issue?我该如何解决这个问题? I am including my package.json
and my directory structure over here.我在这里包括我的package.json
和我的目录结构。
This is the error:这是错误:
> 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
This is my package.json
file of my react project.这是我的反应项目的package.json
文件。 I have edited it by adding "start":"node index.js"
.我通过添加"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"
}
}
My Directory tree is as follows我的目录树如下
-ReactProject
-node_modules
-public
-src
->index.js
-package.json
-package-lock.json
My index.js
file resides inside the src
folder.我的index.js
文件位于src
文件夹中。 The node_modules
, public
, src
, package.json
and package-lock.json
files are on the same line. node_modules
、 public
、 src
、 package.json
和package-lock.json
文件在同一行。
The start script refers to index.js
, but you don't have such a file - it's under src/index.js
.启动脚本引用index.js
,但您没有这样的文件 - 它位于src/index.js
下。 You could either move it to the project root, or update the start
script accordingly:您可以将其移动到项目根目录,或相应地更新start
脚本:
"scripts": {
"start": "node src/index.js"
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.