0

this is my package.json file:

{
  "name": "martina",
  "version": "1.0.0",
  "description": "d",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "d"
  },
  "author": "",
  "license": "ISC"
}

what should I do? I have a Mac by the way!

EDIT: I did what you guys recommended and added the script start, but now when I run 'npm start' I get this:

> [email protected] start /Users/martina
> node index.js

internal/modules/cjs/loader.js:589
    throw err;
    ^

Error: Cannot find module '/Users/martina/index.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:587:15)
    at Function.Module._load (internal/modules/cjs/loader.js:513:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:760:12)
    at startup (internal/bootstrap/node.js:303:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:872:3)
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 WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/martina/.npm/_logs/2020-06-11T08_05_28_654Z-debug.log
4
  • Duplicate: stackoverflow.com/q/31976722/1233251 Commented Jun 10, 2020 at 22:01
  • I believe start needs to be in the "scripts" section of package.json; right now you only have test as a script. I would look into how to include an actual start script. Commented Jun 10, 2020 at 22:02
  • Does this answer your question? Start script missing error when running npm start Commented Jun 10, 2020 at 22:30
  • @Martina, have a look at the PS of my answer. Commented Jun 11, 2020 at 9:11

3 Answers 3

1

You need to add a start script under scripts, and to host or start the application on local node server, add the command node index.js as the value for start script.

{
  "name": "martina",
  "version": "1.0.0",
  "description": "d",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "d"
  },
  "author": "",
  "license": "ISC"
}

PS: While running the command npm start, make sure that you are in the correct project directory. The file index.js and package.json needs to be present as the direct childs of this project directory.

Project Structure:

martina
  |- index.js
  |- package.json
  |- file1
  |- file2
  |- ...other files
  ...

See in the above project structure, martina is the main project directory. And inside martina, index.js and package.json can be found.

Sign up to request clarification or add additional context in comments.

4 Comments

how do you verify if the files are in the right project directory?
@Martina, Have a look at the PS. Updated again
thank you so much! I fixed that! now that everything is in the right place, i get an error: import React from 'react' SyntaxError: Unexpected identifier. it seems to be highlighting React so that should be the error. any idea why?
Can you kindly accept the answer and open a new question for your error, so that will be easy to debug.
1

You need to add a start script under scripts, i.e.:

{
  "name": "martina",
  "version": "1.0.0",
  "description": "d",
  "main": "index.js",
  "scripts": {
    "start": "echo STARTING...",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "d"
  },
  "author": "",
  "license": "ISC"
}

Try npm run test to get an idea of how the scripts field works for package.json.

Comments

-1
{
  "name": "martina",
  "version": "1.0.0",
  "description": "d",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "d"
  },
  "author": "",
  "license": "ISC"
}

Your package appears by looking at the file. That you have just created the project. It seems that the directory of your index.js file in not correct. you create the index.js file in the package.json directory itself, after that run the node index.js or npm start command

> [email protected] start /Users/martina
> node index.js

internal/modules/cjs/loader.js:589
    throw err;
    ^

Error: Cannot find module '/Users/martina/index.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:587:15)
    at Function.Module._load (internal/modules/cjs/loader.js:513:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:760:12)
    at startup (internal/bootstrap/node.js:303:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:872:3)
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 WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/martina/.npm/_logs/2020-06-11T08_05_28_654Z-debug.log

Try this one. Your solution will be done. If you still get an error then let me know

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.