Borislav Hadzhiev
Sun Mar 27 2022·2 min read
Photo by Luke Braswell
The Missing script: "dev" error occurs for multiple reasons:
dev
script in the scripts
section of your package.json
file.package.json
file.package.json
file for your project.scripts
objects in your package.json
file.To solve the Missing script: "dev" error, make sure to add a dev
command to
the scripts
object in your package.json
file and open your shell or IDE in
the root directory of your project before running the npm run dev
command.
First, make sure your package.json
file has a dev
command in the scripts
object.
{ "scripts": { "dev": "node index.js" } }
The dev
command in your package.json
file depends on your setup and the
environment your code is ran in.
If the command is named something else in your package.json
file, you either
have to rename it to dev
, or run the command with its specified name, e.g.
npm run development
.
If you have a dev
command in the scripts
object in your package.json
file,
make sure you are opening your IDE and shell in the root directory of your
project.
package.json
file is to be able to run the npm run dev
command.If you try to run the command from a different directory, it won't find your
package.json
file and the Missing script: "dev" npm error is caused.
If you don't have a package.json
file, you have to create one by opening your
terminal in your project's root directory and running the command npm init -y
.
npm init -y
Now you are able to add a dev
command in the scripts
object of your
package.json
file.
{ "scripts": { "dev": "node index.js", } }
scripts
objects in your package.json
file.This causes the error because the second scripts
object overrides the first,
and your dev
command might only be present in your first scripts
object.
If you don't want to add a dev
command to the scripts in your package.json
file, you can run the command directly from your shell (assuming you have the
specific package installed globally).
node index.js