428

I'm receiving this error when trying to debug my node application using the npm start command.

Error:
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v0.12.7
npm ERR! npm  v2.11.3

npm ERR! missing script: start
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\andrmoll.NORTHAMERICA\Documents\GitHub\SVIChallenge\npm-debug.log
From the debug file:
Error: missing script: start
       at run (C:\Program Files\nodejs\node_modules\npm\lib\run-script.js:142:19)
       at C:\Program Files\nodejs\node_modules\npm\lib\run-script.js:58:5
       at C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:345:5
       at checkBinReferences_ (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:309:45)
       at final (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:343:3)
       at then (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:113:5)
       at C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:300:12
       at evalmachine.<anonymous>:334:14
       at C:\Program Files\nodejs\node_modules\npm\node_modules\graceful-fs\graceful-fs.js:102:5
       at FSReqWrap.oncomplete (evalmachine.<anonymous>:95:15)
BinaryButterfly
  • 18,137
  • 13
  • 50
  • 91
Andrew Moll
  • 4,903
  • 2
  • 13
  • 15

36 Answers36

538

It looks like you might not have defined a start script in your package.json file or your project does not contain a server.js file.

If there is a server.js file in the root of your package, then npm will default the start command to node server.js.

https://docs.npmjs.com/misc/scripts#default-values

You could either change the name of your application script to server.js or add the following to your package.json

"scripts": {
    "start": "node your-script.js"
}

Or ... you could just run node your-script.js directly

Robbie
  • 18,750
  • 4
  • 41
  • 45
  • 24
    I'm struggling to understand, what is the need for `start` when you have `main`? – Val Oct 03 '16 at 11:11
  • 11
    @Val `main` is the entry point into a module when you use `require('your-module')` to include it in another project - https://docs.npmjs.com/files/package.json#main. `scripts.start` is the script to be run by npm when you type `npm start`. – Robbie Oct 11 '16 at 18:31
  • Unclear why `npm init` does not ask about start script. Or at least doesn't use `main` as a start script. – eleven Nov 06 '16 at 16:53
  • 1
    No need to do any thing more just add "scripts": { "prestart": "npm install", "start": "http-server -a localhost -p 8000 -c-1" }, – SantoshK May 23 '18 at 05:12
  • In my case it work fine.. "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "start": "parcel index.html", "build": "parcel build --public-url . index.html" }, – Udit Sharma Nov 05 '19 at 11:20
  • I was doing `npm my-script.js` instead of `node my-script.js`. – Mohammad Zaid Pathan Dec 21 '20 at 21:23
  • this worked for me i had to run npm run dev as dev had the command to run – Amol Bhandari SJ Jul 08 '21 at 11:14
  • Just pointing out that setting `"scripts": { "start": "node ." }` will cause `npm start` to always launch whatever `main` is pointing to. By default `npm start` runs `node server.js` if there is no `start` script defined. See official doc here: https://docs.npmjs.com/cli/v7/commands/npm-start – jmjohnson85 Apr 06 '22 at 18:09
  • What if it is not inside a project? I try to create node app and I have the same problem – Yannick Mussche Sep 23 '22 at 08:08
62

I had this issue while installing react-js for the first time : These line helped me solve the issue:

npm rm -g create-react-app
npm install -g create-react-app
npx create-react-app my-app

source: https://stackoverflow.com/a/59260128/11652661

nofoobar
  • 2,826
  • 20
  • 24
52

add this inside package.json file before closing the "}"

,"scripts": {
  "start": "react-scripts start",
  "build": "react-scripts build",
  "test": "react-scripts test",
  "eject": "react-scripts eject"
}
Taher
  • 11,902
  • 2
  • 28
  • 44
Dima Dorogonov
  • 2,297
  • 1
  • 20
  • 23
45

This error also happens if you added a second "scripts" key in the package.json file. If you just leave one "scripts" key in the package.json the error disappears.

Plamen Petkov
  • 509
  • 4
  • 5
  • 2
    This answer may not be an exact response, but it certainly helped me to find why ```npm start``` was not working. – Obromios Mar 13 '16 at 22:09
  • 3
    This actually is an exact response. If your package.json file contains two entries for scripts, it will chose the second one and ignore whatever you noted in the first. And you will get the error message in the question. – marius Sep 15 '16 at 08:12
  • 2
    @Plamen Petkov, do you mean `scripts` rather than `script`? (Missing an `s`?) – Henke Jul 10 '20 at 08:31
  • This was exactly my case, that's why it was ignoring my first scripts key. Thanks! – Sam Jul 14 '22 at 06:57
30

I just stumbled upon this issue. I reinstalled NPM, created a new React app (so basically a clean install) and still no luck. Finally figured it out:

My terminal was NOT in the correct location.

I had to changedirectory one level deeper into my app. So my terminal was in my 'projects' folder instead of my 'my-app' folder

Path: '/Documents/projects/my-app'

Don H
  • 659
  • 7
  • 9
  • I had clicked `Duplicate tab` in Windows terminal and didn't verify the location. Apparently, it opened it one level above, as you are describing. Thanks! – Evgeny Urubkov May 30 '22 at 19:13
21

Hope it might help someone. This error also happens if you didn't open your project from the root of the project. Make sure to cd into the folder before opening it inside VS code.

LaCodeM
  • 645
  • 7
  • 23
11

You might have an old (global) installation of npm which causes the issue. As of 12/19, npm does not support global installations.

First, uninstall the package using:
npm uninstall -g create-react-app

Some osx/Linux users may need to also remove the old npm using:
rm -rf /usr/local/bin/create-react-app

This is now the only supported method for generating a project:
npx create-react-app my-app

Finally you can run:
npm start

Ali
  • 664
  • 3
  • 13
  • 21
10

Try this method it will work for you
Try this Method it will work 100 %

GHULAM NABI
  • 498
  • 5
  • 15
9

Please use the below line of code in script object which is there in package.json

"scripts": {
    "start": "webpack-dev-server --hot"
}

For me it worked perfectly fine.

slfan
  • 8,950
  • 115
  • 65
  • 78
Ray
  • 280
  • 3
  • 4
6

Try with these steps :

npm rm -g create-react-app

npm install -g create-react-app

npx create-react-app my-app

Definitely this works!!

Srinivasan N
  • 733
  • 8
  • 9
3

I had a similar issue while installing react-js for the first time : These line helped me solve the issue:

npm uninstall -g create-react-app
npm rm -g create-react-app
npm install -g create-react-app
npx create-react-app my-app

this worked in my case.

cherry
  • 336
  • 1
  • 2
  • 9
2

If you are using babelify and watchify, go to:

package.json

and add this in "scripts":

"scripts": {
    "start": "watchify the-path-to-your-source-jsx-file -v -t [ babelify --presets [ react ] ] -o the-path-to-your-output-js-file"
}

An example would be:

"scripts": {
    "start": "watchify src/main.jsx -v -t [ babelify --presets [ react ] ] -o public/js/main.js"
}

Thanks to Mark Price from DevSlopes

SagarPPanchal
  • 9,839
  • 6
  • 34
  • 62
drjorgepolanco
  • 7,479
  • 5
  • 46
  • 47
2

check package.json file having "scripts" property is there or not. if not update script property like this

{
  "name": "csvjson",
  "version": "1.0.0",
  "description": "upload csv to json and insert it into MongoDB for a single colletion",
  "scripts": {
    "start": "node csvjson.js"
  },
  "dependencies": {
    "csvjson": "^4.3.4",
    "fs": "^0.0.1-security",
    "mongodb": "^2.2.31"
  },
  "devDependencies": {},
  "repository": {
    "type": "git",
    "url": "git+https://github.com/giturl.git"
  },
  "keywords": [
    "csv",
    "json",
    "mongodb",
    "nodejs",
    "collection",
    "import",
    "export"
  ],
  "author": "karthikeyan.a",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/homepage/issues"
  },
  "homepage": "https://github.com/homepage#readme"
}
KARTHIKEYAN.A
  • 18,210
  • 6
  • 124
  • 133
2

In my case, if it's a react project, you can try to upgrade npm, and then upgrade react-cli

npm -g install npm@version
npm install -g create-react-app
Yream
  • 31
  • 1
2

Installing create-react-app globally is now discouraged. Instead uninstall globally installed create-react-app package by doing: npm uninstall -g create-react-app (you may have to manually delete package folder if this command didn't work for you. Some users have reported they had to delete folders manually)

Then you can run npx create-react-app my-app to create react app again.

ref: https://github.com/facebook/create-react-app/issues/8086

1

should avoid using unstable npm version.

I observed one thing that is npm version based issue, npm version 4.6.1 is the stable one but 5.x is unstable because package.json will be configured perfectly while creating with default template if it's a stable version and so we manually don't need to add that scripts.

I got the below issue on the npm 5 so I downgraded to npm 4.6.1 then its worked for me,


ERROR: npm 5 is not supported yet


It looks like you're using npm 5 which was recently released.

Create React Native App doesn't work with npm 5 yet, unfortunately. We recommend using npm 4 or yarn until some bugs are resolved.

You can follow the known issues with npm 5 at: https://github.com/npm/npm/issues/16991


Devas-MacBook-Air:SampleTestApp deva$ npm start npm ERR! missing script: start

Deva
  • 2,386
  • 1
  • 16
  • 16
1

Another possible reason: you're using npm when your project is initialized in yarn. (I did this myself). So it would be yarn start instead of npm start.

RobC
  • 22,977
  • 20
  • 73
  • 80
kbooth1000
  • 71
  • 3
1

As per the react documentation https://create-react-app.dev/docs/getting-started/ The following commands will resolve the issue.

npx create-react-app my-app
cd my-app
npm start
LinusGeffarth
  • 27,197
  • 29
  • 120
  • 174
Vignesh_A
  • 508
  • 1
  • 7
  • 19
1

I was having the same issues. I was trying to start it at the VS code terminal. So I start the development environment in my computer terminal (not inside the VS Code). It worked. Make sure that you are inside the file in the terminal before you start it

furkanayilmaz
  • 154
  • 1
  • 11
1
npm rm -g create-react-app
npm install -g create-react-app
npx create-react-app my-app

!important: Make sure you need to chnage the directory to my-app and then hit "npm start"

As you can see in the image , there was an error and it was fixed after chnaging the directory. enter image description here

Sachindra N. Pandey
  • 1,177
  • 17
  • 15
  • Please review *[Why not upload images of code/errors when asking a question?](https://meta.stackoverflow.com/questions/285551/)* (e.g., *"Images should only be used to illustrate problems that* ***can't be made clear in any other way,*** *such as to provide screenshots of a user interface."*) and [do the right thing](https://stackoverflow.com/posts/75199625/edit) (it covers answers as well). Thanks in advance. – Peter Mortensen Mar 04 '23 at 00:08
0

Make sure the PORTS ARE ON

var app = express();
app.set('port', (process.env.PORT || 5000));

BLAL BLA BLA AND AT THE END YOU HAVE THIS

app.listen(app.get('port'), function() {
    console.log("Node app is running at localhost:" + app.get('port'))
});

Still a newbee in node js but this caused more of this.

Goodlife
  • 3,822
  • 2
  • 24
  • 23
0

Take a look at your client/package.json. You have to have these scripts

"scripts": {
  "start": "react-scripts start",
  "build": "react-scripts build",
  "test": "react-scripts test --env=jsdom",
  "eject": "react-scripts eject"
}
0

I got this error because I wasn't in the right directory in terminal.

App with the scripts was in folder B. Folder B was in folder A. I open folder A in vscode and enter "npm run start" into the built in terminal and got the error. try "cd folder B", opening folder B in the ide, or organizing your stuff better than I did in the first place.

thatguy1155
  • 102
  • 1
  • 8
0

I got that same error when I tried run "npm run start"

And my project should starts up with "npm run serve"

If you copy a github project you can look over project setup there like that one: enter image description here

So always make sure you run it with the right command, in my case was

npm run serve
  • Your cloned project should have a script name like "serve". Otherwise this will not work. The default script name to start the react project is "start". But most important thing is you can change it to a whatever name you want. Look your cloned project's "package.json" file. Inside it, in the "script" property you should see something like "serve": "react-scripts start" or "serve:": "node index.js". So I think, now you can understand what has happened in your project. – Sapthaka Oct 19 '21 at 14:54
0

Check it package.json file out and find your script name in this file

yusufgltc
  • 51
  • 5
0

I had this error after create a react project in vscode. After closing and reopening the vscode and create a new terminal in cmd mode in vscode, the problem resolved.

M Komaei
  • 7,006
  • 2
  • 28
  • 34
0

There are more answers regarding to scripts. Here is my 2 cents. If you having the same issue just after creating the react app or just started the work in the day, in most case this is what happened. You may not got inside of the created project.

Suppose you created a react app as my-app. then you have to go inside of the app before you run nmp start command.

1. cd my-app

2. npm start

It will work fine.

0

Check if you have nodemon installed, if you do, run the script using nodemon the start script in your package.json Example nodemon start

Apesin
  • 26
  • 2
  • This question is asked more than 7 years ago and it has an accepted answer. Please add some details about the reason you are adding a new answer – MD Zand Nov 29 '22 at 20:27
0

For my example, I created a React project in "First" folder and I run the project in this folder, so I saw the same error.

You should enter in the project, and then you should run (for my example "react-movies"). You can easily realize if you look at my PowerShell screen.

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • Please review *[Why not upload images of code/errors when asking a question?](https://meta.stackoverflow.com/questions/285551/)* (e.g., *"Images should only be used to illustrate problems that* ***can't be made clear in any other way,*** *such as to provide screenshots of a user interface."*) and [do the right thing](https://stackoverflow.com/posts/75316315/edit) (it covers answers as well). Thanks in advance. – Peter Mortensen Mar 04 '23 at 00:02
0

Also, do remember to change directory into the exact folder where you server was installed. You will get this error if you run the npm start command from a parent folder of your project.

That was how I got this error.

Neil Meyer
  • 473
  • 4
  • 15
0

run it using this if you don't have server.js or start in package.js

npm run dev
General Grievance
  • 4,555
  • 31
  • 31
  • 45
0

This method worked for my self

1st one

npm rm -g create-react-app

2nd one

npm install -g create-react-app

3rd one

npx create-react-app my-app

//This process takes some time.

0

This Could be happen due to choosing wrong directory. for windows command 'dir' on console watch out directories in current by './' select that directory. for example in mycase : MyReactApp(folder)>reactapp>reactapp it creates subdirectory of reactapp where we run project

-1
"scripts": {
  "prestart": "npm install",
  "start": "http-server -a localhost -p 8000 -c-1"
}

add this code snippet in your package.json, depending on your own configuration.

RobC
  • 22,977
  • 20
  • 73
  • 80
-1

I have the same issue. I try to write a code in package.json file as below

    "scripts": {
    "start": "<your-script-file>.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
Mohamed Salah
  • 160
  • 1
  • 5
-2

I have solved mine. Its not an NPM Error its related to proxy behavior.

If you are behind proxy,

MAC
 1.  Goto System Preference (gears icon on your mac)
 2.  click your network
 3.  click advanced
 4.  click proxy
 5.  check excludes simple hostnames
 6.  add this line below (Bypass Proxy Settings...) "localhost, localhost:8080"

refer to the npm echo: "Project is running at http://localhost:8080/"

Windows
 1.  Goto your browser Proxy Settings (google it)
 2.  check Bypass local address
 3.  add this line below "localhost, localhost:8080"
Eman Jayme
  • 230
  • 2
  • 8