Fix "npm ERR! Missing Script: dev"

By 

•

Published on

•

6 min read

A dev command tile being added to an empty row in a package.json scripts card

You clone a project, install its dependencies, and run npm run dev. Instead of a development server, npm reports Missing script: "dev". This means the package npm selected does not define a script named dev.

This guide explains how to check the available scripts, select the correct project or workspace, and add a development command when one is missing.

What the Error Means

Recent npm versions show a message like this:

output
npm error Missing script: "dev"
npm error
npm error To see a list of scripts, run:
npm error   npm run

Older versions use the npm ERR! prefix instead of npm error, but the meaning is the same. When you run npm run dev, npm looks in the scripts object of package.json for a key named dev. If the key is missing, npm stops before it runs a development server.

The script may be absent, named differently, or defined in another package. Reinstalling dependencies or clearing the npm cache does not add a missing script to package.json.

List the Scripts That Actually Exist

Start by asking npm what scripts the project defines. Running npm run with no argument lists the available scripts:

Terminal
npm run

For example, a Vite project that uses start for its development server might show:

output
Lifecycle scripts included in my-app@1.0.0:
  start
    vite
available via `npm run`:
  build
    vite build
  preview
    vite preview

This example has no dev script, but its start script runs vite, which starts Vite’s development server. You can run that script with:

Terminal
npm start

Check the command behind each script and the project’s README before choosing one. A name such as start or serve does not guarantee a development server. In particular, vite preview previews a production build, and next start starts Next.js in production mode after a build.

Check You Are in the Right Directory

If the expected script does not appear, check which project directory you are in and whether it contains a package.json:

Terminal
pwd
ls package.json

The first command prints your current directory, and the second checks for a package.json there. npm can find a package in a parent directory, so running a command from a subdirectory does not necessarily select a different package. However, running from an unrelated project or a monorepo root can select a package without the script you need.

Change into the directory containing the application’s package.json, replacing my-app with your project path, and list its scripts again:

Terminal
cd my-app
npm run

Select the Correct Workspace

In an npm workspace project, the root package and each application can have different scripts. If the root package.json declares packages/web as a workspace, you can list that package’s scripts from the root with:

Terminal
npm run --workspace=packages/web

If the output lists dev, run it in the same workspace:

Terminal
npm run dev --workspace=packages/web

Replace packages/web with your workspace’s directory or package name. The --workspace option selects a workspace configured in the root package.json; it does not turn an arbitrary folder into a workspace.

Fix a Misnamed Script

Script names are case-sensitive and must match exactly. Dev, dev, and dev:web are different keys. Compare what you typed against the output of npm run and use the exact name. If the project defines dev:web, run:

Terminal
npm run dev:web

The colon is part of the script name. npm does not run dev:web when you ask for dev.

For close matches, such as a different capital letter, npm adds a Did you mean this? line with the correct command. It does not suggest longer names such as dev:web, so check the npm run list as well.

Add the Missing Script

If you have confirmed the correct package and it should have a dev script, add the command that matches the project’s existing tools. Check its dependencies, devDependencies, and README first.

For the Vite example above, add "dev": "vite" inside the existing scripts object. The scripts would then look like this:

package.jsonjson
{
  "scripts": {
    "dev": "vite",
    "start": "vite",
    "build": "vite build",
    "preview": "vite preview"
  }
}

This snippet shows only the scripts object. Keep the other fields and existing scripts in your file, and do not create a second scripts object. JSON requires double quotes and does not allow trailing commas.

The key on the left is the name you pass to npm run; the value on the right is the shell command npm executes. Save the file, then run:

Terminal
npm run dev

With this configuration, npm runs Vite’s development server. The Vite guide documents the dev, build, and preview commands. A Next.js app uses "dev": "next dev" instead. For a plain Node.js application, the command might be "dev": "node server.js", with server.js replaced by the actual entry file. Use the tool your project already uses rather than adding a framework just to make the error disappear.

Troubleshooting

npm run lists no scripts at all
The selected package may have no scripts object, or it may be empty. Check the package’s README and confirm you are in the intended application before adding commands. A library package does not necessarily need a development server.

npm reports ENOENT and cannot open package.json
npm could not read the package file at the path shown in the error. Change into the existing project’s directory and check that its package.json was included when you cloned or extracted it. Running npm init -y creates a new package file; it does not restore a cloned application’s scripts.

npm reports EJSONPARSE after editing package.json
The file contains invalid JSON. Check the line shown in the error for a missing comma, an unquoted key, a comment, or a trailing comma. This is a parsing error, separate from a missing script.

The script exists but npm still reports it missing
Save your editor changes and run npm run again in the same package or workspace. Check that dev is inside the top-level scripts object and spelled exactly as you typed it. If you see a different package name in the output, check the directory or workspace selection.

The error changes to vite: not found or next: not found
npm has found the script, but the tool it calls is unavailable. Run npm install in the project, or at the root of an npm workspace project, to install its declared dependencies. If NODE_ENV is set to production, or your npm config sets omit=dev, npm skips development dependencies; run npm install --include=dev to install them. If the repository specifies another package manager, follow its installation instructions instead.

Conclusion

If you add a dev script, keep the existing start script as well, since the README or CI configuration may still call it. For more on running scripts and managing project dependencies, see our npm command guide .

Tags

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page