npm ERR! Missing script: "start" [Solved]

avatar

Borislav Hadzhiev

Last updated: Sep 10, 2022

banner

Photo from Unsplash

npm ERR! Missing script: "start" [Solved] #

The npm ERR! Missing script: "start" error occurs for multiple reasons:

  1. Missing a start script in the scripts section of your package.json file.
  2. Opening your IDE or shell in a directory that doesn't contain your package.json file.
  3. Not having initialized a package.json file for your project.
  4. Using an outdated version of a package, e.g. create-react-app.
  5. Having multiple scripts objects in your package.json file.

npm missing script start

shell
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

To solve the npm ERR! Missing script: "start" error, make sure to add a start command to the scripts object in your package.json file and open your shell or IDE in the root directory of your project before running the npm start command.

First, make sure your package.json file has a start command in the scripts object.

package.json
{ "scripts": { "start": "node index.js" } }

The start command in your package.json file depends on your setup and the environment your code is run in.

package json scripts section

If you have a start command in the scripts object in your package.json file, make sure you are opening your IDE and shell in the root directory of your project.

You should open your IDE or shell in the directory where your package.json file is to be able to run the npm start command.

If you try to run the command from a different directory, it won't find your package.json file and the Missing script: "start" npm error is caused.

If you don't have a package.json file, create one by opening your terminal in your project's root directory and running the command npm init -y.

shell
npm init -y

Now you can add a start command in the scripts object of your package.json file.

package.json
{ "scripts": { "start": "node index.js", } }
Another cause of the error is having multiple scripts objects in your package.json file.

This causes the error because the second scripts object overrides the first, and your start command might only be present in your first scripts object.

If you don't want to add a start command to the scripts in your package.json file, you can run the command directly from your shell (assuming you have the specific package installed globally).

shell
node index.js

If you use create-react-app, the error might be caused by an outdated version. Open your shell and run the following commands.

shell
# 👇️ uninstall old version npm uninstall -g create-react-app # 👇️ clear your cache npx clear-npx-cache # 👇️ to create normal React.js project npx create-react-app my-app # 👇️ to create TypeScript React.js project npx create-react-app my-app --template typescript

If the suggestions above didn't work, try running the command with the --use-npm flag.

shell
# 👇️ for normal React.js project npx create-react-app@latest my-app --use-npm # 👇️ for TypeScript React.js project npx create-react-app@latest my-app --template typescript --use-npm

Conclusion #

To solve the npm ERR! Missing script: "start" error, make sure to add a start command to the scripts object in your package.json file and open your shell or IDE in the root directory of your project before running the npm start command.

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.