Skip to main content

Missing script

This error appears when you've used npm run[-script] to try to run one of the package scripts provided in the scripts object inside package.json, but have either mistyped the name or simply tried to run one that doesn't exist in that particular package.

npm run

Run arbitrary package scripts

$ npm run dev
npm ERR! Missing script: "dev"
npm ERR!
npm ERR! To see a list of scripts, run:
npm ERR! npm run

npm ERR! A complete log of this run can be found in: path/to/.npm/_logs/{filename}.log

This might seem tautological - the script is missing because the script is missing. But there are a couple of common causes, which we'll go through in order of likelihood.

Typo in script name

First, check you haven't made a simple typo (e.g. entered npm run bulid instead of npm run build). If what you've typed is similar to one of the built-in commands or matches the start of something that is in the available scripts, npm will show suggestions:

$ npm run buil
npm ERR! Missing script: "buil"
npm ERR!
npm ERR! Did you mean this?
npm ERR! npm run build # run the "build" package script
# ...

Read through these suggestions carefully, as one might be what you actually intended (and even if not you might learn about some interesting npm functionality you hadn't previously been aware of!)

Wrong package

If the script name is typed correctly, ensure you're in the right package. You can use the standard pwd command to show which working directory you're currently in, but more useful is to see which directory npm is using, i.e. where it's looking for package.json, which you can do with npm prefix:

npm prefix

Display prefix

$ npm prefix
path/to/wtf-npm

If you find you're in the wrong place, cd to an appropriate working directory and try to run the script again.

Different conventions

If you've typed the script name correctly and you're in the right place, then it's likely you're used to packages with different conventions for their entrypoints. For example:

  • CRA-created React apps use npm run start for the local development mode; whereas
  • Vite-created React apps use npm run dev.

As it suggests in the error message, npm run[-script] without any additional arguments can be used to show the full list of all available scripts, e.g. for this repository:

$ npm run
Lifecycle scripts included in [email protected]:
start
docusaurus start

available via `npm run-script`:
build
docusaurus build
clear
docusaurus clear
deploy
gh-pages --dist build
docusaurus
docusaurus
serve
docusaurus serve
swizzle
docusaurus swizzle
typecheck
tsc
write-heading-ids
docusaurus write-heading-ids
write-translations
docusaurus write-translations

Look through the list to see which one does the thing you'd intended to do. For a shorter, JSON-formatted representation of the available scripts, you can use npm pkg:

npm pkg

Manages your package.json

$ npm pkg get scripts
{
"build": "docusaurus build",
"clear": "docusaurus clear",
"deploy": "gh-pages --dist build",
"docusaurus": "docusaurus",
"serve": "docusaurus serve",
"start": "docusaurus start",
"swizzle": "docusaurus swizzle",
"typecheck": "tsc",
"write-heading-ids": "docusaurus write-heading-ids",
"write-translations": "docusaurus write-translations"
}

Create an alias

Note you can always add your own aliases for existing scripts - if you'd like to use npm start instead of npm run dev in a Vite-based React project, for example, you can either edit the package.json directly or use npm pkg to update it:

$ npm pkg set scripts.start='npm run dev'

This allows you to keep consistent entrypoints across different projects using different frameworks.