How to fix npm ERR! missing script: start issue

Posted on Jun 23, 2022

Learn how to fix the npm ERR missing script start error.

Photo from Unsplash

The npm error missing script: “start” means that npm can’t execute the “start” script from your package.json file.

This error happens when you run the npm start or npm run start command from the command line.

Here’s an example of the error message in the terminal:

$ npm run start
npm ERR! Missing script: "start"
npm ERR!
npm ERR! Did you mean one of these?
npm ERR!     npm star # Mark your favorite packages
npm ERR!     npm stars # View packages marked as favorites
npm ERR!
npm ERR! To see a list of scripts, run:
npm ERR!   npm run
...

The npm start command will look into the scripts section of your package.json file for the start script.

An example of the start script is as follows:

{
  "name": "v-app",
  "version": "1.0.0",
  "scripts": {
    "start": "node index.js"
  }
}

The example above defines the start script to run the code inside index.js file using node JavaScript server.

If the start script is not defined, then npm will try to look for a server.js file in the root directory of your project.

When npm can’t find the start script and server.js file, then it will trigger the missing script start error.

To resolve the missing script: “start” npm error, you need to define the start script in your package.json file like in the example.

What you write in the start script depends on the configuration of your project.

If you don’t have a package.json file, then it’s possible that you have accidentally deleted the file. You need to get the package.json file back.

Once you added the start script to the scripts section as shown above, the npm start command should work.

Make sure you have no duplicate scripts section

Sometimes, the error happens because you have duplicate scripts section in the package.json file.

There are two scripts section in the example below:

{
  "name": "v-app",
  "version": "1.0.0",
  "scripts": {
    "start": "node index.js"
  },
  "scripts": {
    "dev": "gulp"
  }
}

When you have more than one scripts section, then npm will read only the latest entry at the bottom of the file.

You can check the available scripts using the npm run command like this:

$ npm run
Scripts available in v-app@1.0.0 via `npm run-script`:
  dev
    gulp

The above shows that npm can’t find the start script.

To resolve this issue, you need to merge the two scripts section as one:

{
  "name": "v-app",
  "version": "1.0.0",
  "scripts": {
    "start": "node index.js",
    "dev": "gulp"
  }
}

Save the file changes, then run the npm run command again to verify the error has been solved

$ npm run
Lifecycle scripts included in v-app@1.0.0:
  start
    node index.js

available via `npm run-script`:
  dev
    gulp

As you can see, the terminal output from npm run is different. The start script is now available.

Missing start script because of create-react-app

The missing script start issue is also known to happen when you create a new React project using create-react-app as follows:

create-react-app my-app

This is because create-react-app no longer support the global install, as stated in its website.

To resolve the issue, you need to use the latest version of create-react-app with npx.

Run the following commands step by step:

# 👇 remove the globally installed package
npm uninstall -g create-react-app

# 👇 clear npx cache to ensure you use the latest cra version
npx clear-npx-cache

# 👇 run create-react-app with npx
npx create-react-app my-app

npx will fetch the latest version of create-react-app to create the new project.

Once the project is created, you can verify that the scripts section is available inside the package.json file as follows:

{
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
}

Now you should be able to run npm start from your React application.

And that’s how you fix the npm ERR! missing script: start issue. Nice job! 👍

Level up your programming skills

I'm sending out an occasional email with the latest programming tutorials. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.