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 :
So how do we solve the missing script: dev error?
Fixes for this error are very simple, just follow the solutions below.
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.
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.
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 .
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.