(Fixed) npm ERR! missing script: start error

featured Image

In this article, we will learn how to fix npm err! missing script start error in node application.

This error usually shows up when we run the command npm start to start our development server in nodejs.

npm ERR! missing script: start issue

Reasons npm ERR! missing script: start issue

We get the error when we run the npm start or the npm run start command on our terminal.

The npm start command checks for the start script in the package.json file.

Here, is an example of the start script in the package.json file.

{
  "name": "my-project",
  "version": "1.1.0",
  "scripts": {
    "start": "node index.js"
  }
}

The start script tells node to run the code inside the file index.js file.

Now, the npm missing script error can occur for the following reasons:

  1. missing start script in the package.json file.
  2. The root folder doesn’t have the package.json file.
  3. The package.json file is not initialized in your project.
  4. Having multiple script objects in package.json file.

Fix npm ERR! missing script: start error

To resolve this error in our node application, we just have to define start in the scripts object in the package.jsonfile.

So first identify the root JavaScript file in your application. It can be main.js, app.js or server.js in your application.

Then open your package.json file and find the scripts section.

A default package.json file looks like this,

"scripts": {
  "test": "echo "Error: no test specified" && exit 1"
},

Now add the start script the scripts section after test.

"scripts": {
  "test": "echo "Error: no test specified" && exit 1",
  "start": "node index.js"
},

Replace the index.js by the root file name of your node application. In my case the root file is index.js.

An alternate way, if you don’t want to edit the package.json of your node application, you can just run the main file directly by

node index.js

Missing package.json in Root Folder

Make sure to open your code editor or IDE in the root folder which includes the package.json file.

If you have opened it or run the npm start command from a different folder, it will throw the missing script error.

Package.json file not initialized

If you have not initialized or created the package.json file in your root directory, then you will get the missing start script error when you run npm start command.

To create a package.json file, open your terminal in your project root folder and type:

npm init -y

This command will create the package.json file where you can add the start command in the scripts object.

Multiple scripts object in the project

Next, cause of the error could be that you have added multiple scripts objects in your json file accidentally.

So, delete the extra start scripts in your package.json file.

Conclusion:

Here, we have learned about the npm missing script start error, it cause and the ways to fix it.


Other Articles You’ll Also Like:

Npm WARN Package.Json: No Repository Field

Resolve – Node Unexpected Token Import Error

Resolve Npm Cannot Find Module Error In Nodejs

(Resolved) Cannot Use Import Statement Outside A Module Error

How to fix “npm ERR cb() never called”

npm WARN : No description field in Node – Fix

Fixed Error – npm ERR! missing script: dev

NVM Error – exit status 1: Access is denied – Fixed

Related Posts

git commands with example

Top 40 Git commands with Examples

GitHub has become an essential tool for developers to manage, store, and collaborate with other developers on software projects. With its simple powerful git-based version control system, GitHub allows users…

Read more
Check GitHub Account in the Terminal

Check GitHub Account in the Terminal

GitHub is an integral tool for developers to store, manage, and collaborate on software projects with other developers. And as we work more and more in the command line it…

Read more
featured Image

How to make list of objects in Netlify CMS using list and object Widget

Here in this Netlify CMS tutorial we will how easily we can make a list of objects using list and object widgets. This will allow us to add multiple objects…

Read more

Leave a Reply

Your email address will not be published. Required fields are marked *