1

I am getting an error like the below when I run npm start command to start the server for my first react project. I have tried uninstalling and reinstalling the node.js but did not work. How can I resolve this issue? I am including my package.json and my directory structure over here.

This is the error:

    > [email protected] 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! [email protected] start: `node index.js`
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the [email protected] 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. I have edited it by adding "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. The node_modules, public, src, package.json and package-lock.json files are on the same line.

4
  • Do you have an index.js file in the project's root? Commented Jul 18, 2020 at 10:08
  • Can you show your project file structure and where is the index.js file located Commented Jul 18, 2020 at 10:09
  • I have added my project file structure in the question. Please go through it. @Mureinik . Thank you for responding. Commented Jul 18, 2020 at 13:02
  • @ShauryaVardhanSingh I am glad for your response. I have added the structure in my question area. Please help to resolve the error! Commented Jul 18, 2020 at 13:03

1 Answer 1

3

The start script refers to index.js, but you don't have such a file - it's under src/index.js. You could either move it to the project root, or update the start script accordingly:

"scripts": {
    "start": "node src/index.js"
},
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.