How to fix npm ERR! Missing script: "start"

The npm ERR! missing script: start error occurs when the start script is not defined in your package.json file. To solve this error, define the "start" script in the package.json file.

In express js, the “start” script should be defined as “node server.js” in which server.js is the entry point of the application.

In the case of React application,  the "start" script should be defined as "react-scripts start" to run the development server, define additional scripts such as “build” for building the production version and “test" for running tests.

In this article we going to discuss:

  1. npm ERR! missing script: start error in express.js
  2. npm ERR! missing script: start error in React js

npm ERR! missing script: start error in express.js

npm ERR! missing script: start error happens in express.js when the start script is missing in the package.json file. If the start script is not defined then, npm will look for the server.js file in the root folder to start the server. When the start script and server.js file are missing, then it will throw this error.

To solve this error define the start script inside the package.json file.

Here is an example of a start script for express js.

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

 The above start script will run the index.js file using the node command.

When you don’t have a start script in the package.json file, then npm will try to find a file server.js in your root directory and try to run it. If you are using an index.js file, then rename it into a server.js file to solve this error. Next, start the server using the command “npm start”.

Also, make sure you are not running the npm run start command in a different directory.

npm ERR! missing script: start error in React js

In a React application, npm ERR! missing script occurs due to the following reasons.

  1. Missing a start script in your package.json file.
  2. You may have multiple script objects in the package.json file.

To solve this error, make sure to add "start": "react-scripts start" under scripts in the package.json file. If you have scripts in the package.json file, then the issue may be due to the multiple scripts objects. In such cases, you can remove duplicate script objects to solve this error.

Here is a sample scripts for a react application for npm start, npm build, and npm test commands.

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

The react-scripts is an npm package that has some pre-configured scripts to start a development server, build for production, and run tests. It will be automatically installed and configured when you are using Create React App.

Conclusion

To solve the error npm ERR! Missing script: “start" in express.js, make sure to add a start script in the package.json file or rename the into server.js(file you are going to run). If you are working react application, then add "start": “react-scripts start” under scripts object. Also, check and confirm you are not using multiple scripts in the package.json.