Fixed Error – npm ERR! missing script: dev

featured Image

In this article, we will learn how to fix the npm missing script dev error while running a Javascript application on our computer.

Sometimes when we try to run the development server for a JavaScript project we come across npm errors like this:

npm missing script dev or npm missing script serve

Recently while working on a node project I got the missing dev script error on my terminal like this.

fix the npm missing script dev error

Why do we get this npm error?

Well, there are a few common reasons which cause this error :

  1. Missing dev script in your package.json file
  2. Have a different name assigned to the command in the package.json file.
  3. Running the npm run dev command from a directory that doesn’t have the package.json file.
  4. Missing package.json file from your project.

So how do we solve the missing script: dev error?

Fixes for this error are very simple, just follow the solutions below.

Solution 1: Add the dev script in the package.json file

Open your package.json file in your project and add the dev command in the scripts section of the file.

After that, run the command (npm run dev) from the root directory of the project.

Example:

{
  "name": "myApp,
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "dev": "node index.js", // Add in the scripts field
  },
  "dependencies": {
    "core-js": "^3.9.1",
  },
}

For most users, this fixes the issue.

Solution 2: Check if the command name “dev” is the same in package.json

If a different name is assigned in the package.json file, then renaming it to dev will solve the error.

Example :

{
  "name": "myApp,
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "serve": "node index.js", // different name (serve)
  },
  "dependencies": {
    "core-js": "^3.9.1",
  },
}

Here the command name is serve, so running npm run dev will throw an error in the terminal.

Just renaming serve to dev will solve the issue.

Solution 3: Run the command from the root directory of the project

Make sure you are running the command from the root directory where the package.json is present.

Running the command from a different folder / directory can throw missing script: dev error in the terminal.

Open your IDE or code editor in the root folder where the package.json file is located and then run the command npm run dev .

Solution 4: Initialized package.json file in your project folder

If the package.json file is missing in your project, then you have to create one in the root folder of the project using the command:

npm init -y

The npm init command creates a package.json file for our project’s frontend. This file contains the information about the different npm packages we use in our project.

Once the package.json file is created, you can just add the dev command in the scripts section of the file.

So, these are the four solutions that can fix the missing script: dev error from your JavaScript project.


Related Articles:

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

Solve npm ERR! ENOENT – No Such File or Directory Error

Fix error:0308010C:digital envelope routines::unsupported

How to Clear Cache in NPM?

Solving “npm not recognized as an internal or external command” Error

(Fixed) npm ERR! missing script: start error

npm WARN : No description field in Node – Fix

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 *