Fixing “Missing script” Error in npm run
If you run npm run dev or a similar command in the terminal and see npm error Missing script: "dev", the scripts field in the package.json of the current project has no script with that name. Run npm run with no arguments to see the script names that actually exist, then run one of those names instead, or add the name to scripts. Either way, the error goes away.
This error appears when you type npm run dev (to start a dev server), npm run build, or npm start exactly as a README or setup guide says, and it still does not work. I reproduced this error in a test environment, recorded the full message, and confirmed that it disappears after the fix.
The test environment was Ubuntu 24.04. I mainly tested with Node.js 22.23.4 (npm 10.9.9). For comparison, I ran the same commands with npm 9.9.4 and with npm 11.19.1, which ships with Node.js 24.22.1. I did not test Windows or macOS, yarn or pnpm, or projects that use workspaces.
- 1. The full error text
- 2. First, check the real script names with npm run
- 3. When you mistype a name, a suggestion may or may not appear
- 4. npm start does not fail if server.js exists
- 5. Running from a different folder gives a different error
- 6. Adding the script to scripts fixes it
- 7. If you do not want an error when the script is missing
The full error text
For the test, I created a project with npm init -y, added build to the package.json, and left scripts with just two entries. The scripts part of the package.json was as follows.
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "echo build done"
},
When I specified dev, which is not in scripts, npm 10.9.9 printed the following and stopped (exit code 1; paths are replaced with example values).
$ npm run dev
npm error Missing script: "dev"
npm error
npm error To see a list of scripts, run:
npm error npm run
npm error A complete log of this run can be found in: ~/.npm/_logs/2026-11-12T03_39_21_543Z-debug-0.log
The first line means that there is no script named dev. The lines below it say to run npm run to see the list of scripts. npm 11.19.1 printed the same text.
npm 9.9.4 starts each line with npm ERR!. The output for the same command is below (paths are replaced with example values). Apart from the prefix, the differences were that there is an empty line before the last line, and that the empty npm ERR! line ends with a trailing space.
$ npx -y npm@9.9.4 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: ~/.npm/_logs/2026-11-12T03_39_30_846Z-debug-0.log
First, check the real script names with npm run
As the message says, running npm run without a name prints the list of scripts you can use.
$ npm run
Lifecycle scripts included in app@1.0.0:
test
echo "Error: no test specified" && exit 1
available via `npm run-script`:
build
echo build done
test appears under the Lifecycle scripts heading at the top, and build appears in the lower section, each shown with the command it runs. If dev is not in this list, the project has no dev script. Look at what each script runs and find the name that fits your goal.
When you mistype a name, a suggestion may or may not appear
A mistyped name also produces the same Missing script error. When I typed Build with a capital B, the message included a suggestion (paths are replaced with example values).
$ npm run Build
npm error Missing script: "Build"
npm error
npm error Did you mean this?
npm error npm run build # run the "build" package script
npm error
npm error To see a list of scripts, run:
npm error npm run
npm error A complete log of this run can be found in: ~/.npm/_logs/2026-11-12T03_39_21_909Z-debug-0.log
On the other hand, with biuld, where two letters are swapped, no suggestion appeared, and the message had the same form as the first dev case. npm 9.9.4 and npm 11.19.1 behaved the same way.
In npm 10.9.9, whether a suggestion appears is decided by the logic in lib/utils/did-you-mean.js in the source. It only suggests names whose distance from the typed name (how many characters must change to make them match npm commands, script names, or bin names in package.json) is less than 40% of the typed name's length. Build is one character away from build, which is less than 40% of 5 characters (2), so it is suggested. biuld counts as two characters away from build, which is not less than 2, so it is not suggested. No suggestion does not mean there is no similar script name.
npm start does not fail if server.js exists
Running npm start in a project without a start script also gives Missing script: "start". In this case, npm suggested an npm command with a similar name (paths are replaced with example values).
$ npm start
npm error Missing script: "start"
npm error
npm error Did you mean one of these?
npm error npm star # Mark your favorite packages
npm error npm stars # View packages marked as favorites
npm error
npm error To see a list of scripts, run:
npm error npm run
npm error A complete log of this run can be found in: ~/.npm/_logs/2026-11-12T03_39_22_018Z-debug-0.log
npm star adds a package to your favorites. It does not replace start.
The npm start documentation says that if scripts has no start, npm runs node server.js. I put a server.js file at the top of the project and tried it. Even without a start script, there was no error, and node server.js ran.
$ npm start
> app@1.0.0 start
> node server.js
server.js started
Running from a different folder gives a different error
If the current folder has no package.json, npm run moves up through the parent folders to find one that has a package.json (or node_modules). See the npm documentation on how it determines the project folder. In my test, running npm run build from the src folder inside the project ran the build script from the package.json at the top.
If no package.json is found even after moving up, you get an ENOENT error instead of Missing script (exit code 254; paths are replaced with example values).
$ npm run dev
npm error code ENOENT
npm error syscall open
npm error path /path/to/other/package.json
npm error errno -2
npm error enoent Could not read package.json: Error: ENOENT: no such file or directory, open '/path/to/other/package.json'
npm error enoent This is related to npm not being able to find a file.
npm error enoent
npm error A complete log of this run can be found in: ~/.npm/_logs/2026-11-12T03_39_22_491Z-debug-0.log
Because npm searches upward, if you run the command inside another project's folder, or under a parent folder that has a package.json, npm reads the scripts from that package.json. If you see Missing script and the npm run list is not what you expected, use cd to move to the project folder you want, then run the command again.
Adding the script to scripts fixes it
If the project really needs dev, add it to the scripts in package.json. You can also type it into an editor. In my test I used npm pkg set. The script here only prints some text, so you can see that it ran.
$ npm pkg set scripts.dev="echo dev server started"
$ npm pkg get scripts
{
"test": "echo \"Error: no test specified\" && exit 1",
"build": "echo build done",
"dev": "echo dev server started"
}
When I ran the same command again, there was no error and the script ran (exit code 0).
$ npm run dev
> app@1.0.0 dev
> echo dev server started
dev server started
dev also appeared in the npm run list, below build.
If you do not want an error when the script is missing
Adding --if-present stops npm from failing when the script does not exist. When I ran npm run dev --if-present with no dev script, nothing was printed and the exit code was 0. The npm config documentation also says this option prevents an error exit when you try to run a script that is not in scripts.
With --if-present, a mistyped name does not cause an error either (npm run biuld --if-present also exited with code 0). If you add this flag just to make Missing script go away, you will not notice that the script never ran.





