Fixed Error - npm ERR! missing script: dev
Find out how to fixed npm error, npm missing script dev while running the node serve in your javascript node project.
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.

Why do we get this npm error?
Well, there are a few common reasons which cause this error :
- Missing dev script in your package.json file
- Have a different name assigned to the command in the package.json file.
- Running the npm run dev command from a directory that doesn't have the package.json file.
- 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 Posts
Solve npm ERR! ENOENT - No Such File or Directory Error
Learn what causes the npm ERR! ENOENT error, steps to troubleshoot it, and how to fix the no such file or directory issue when running npm start or npm install commands on your Node.js project.
How to Clear Cache in NPM?
In this tutorial we will learn how to clean or remove npm cache from Windows, linux and Mac using npm cache clean command.
How to Downgrade an Installed npm Package
Learn how to downgrade npm packages for compatibility issues, bug fixes, new features, or personal preference. Follow step-by-step guide for a easy downgrade process.
(Fixed) npm ERR! missing script: start error
This article is about how to fix npm err! missing script start error in nodejs application.
