[Solved] npm err! missing script: start 

Total
24
Shares

The npm err! missing script: start occurs if you have not defined the start script in the package.json file or your application doesn’t have a server.js file which node will invoke the server.js to run the application.

In this tutorial, we will take a look at what exactly npm err! missing script: start means and how to resolve the issue with examples.

How to fix npm err! missing script: start

If you are working on the React, node.js type of applications, you would have encountered this issue.

The main reason behind this error is missing the start script in the package.json file.

The package.json is the heart of any node.js application. It holds all the metadata information, dependencies, build scripts, etc.

Unless you define the start script and provide the entry file path in the package.json, node.js won’t know the main entry file to run the application, and hence it throws an error npm err! missing script: start

Solution 1 – Add the Start Scripts in package.json

If you are running the node.js application, add the start script and entry file in the package.json to resolve the issue. If you are running a react application, add the start script as shown below to resolve the issue.

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

Solution 2 – Ensure you have server.js or add the main file in the start script

The start script is not always mandatory in many cases, and we can simply add the server.js file as an entry point to the application or set the relevant script file as the entry point in the package.json, as shown below.

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

Solution 3 – Directly run the Node.js script

You can even run the script directly by using the node command. Let’s say you have created a script and want to run using node. You can run it using the below command.

node your-script.js

Solution 4 – Verify the project path before using npm run start command

If you are new to development and following the tutorials to create a new react project and run it for the first time, ensure that you are in the right folder path when running the application using the npm run start command.

Also ensure that you do not have a duplicate script key in the package.json file.

Conclusion

The npm err! missing script: start mainly occurs if you have not specified the entry path in package.json to run the application. 

We can resolve this issue by editing the package.json file and defining the start script path. Alternatively, we can also create a server.js file and specify that as the main entry path in the package.json file.

1 comment
Leave a Reply

Your email address will not be published.

Sign Up for Our Newsletters

Get notified on the latest articles

You May Also Like