How to fix npm ERR! Missing script: in npm
The "missing script" error occurs when you try to run an npm script that doesn't exist in package.json. Check your script name spelling or add the missing script to package.json.
Quick fix
Fixes npm ERR! Missing script:
npm run
# Or view directly
cat package.json | jq .scripts- List available scripts
- Check script name spelling
- Verify correct directory
- Add the missing script
npm run# Or view directlycat package.json | jq .scriptsnpm ERR! Missing script:
What this error means
npm run <script> looks for the script in your package.json's "scripts" object. If the script name isn't found, npm reports this error. This often happens with typos, when running commands from tutorials that assume certain scripts exist, or when switching between projects with different script configurations.
Typical symptoms
- npm run command fails with "missing script"
- Script name misspelled
- Copied command from tutorial
- Script exists in different project
- Script was renamed or removed
- Wrong directory
Common causes
- Typo in script name
- Script not defined in package.json
- Running in wrong directory
- Script removed or renamed
- Using wrong project's commands
- Tutorial assumes script exists
How to fix "npm ERR! Missing script:"
See what scripts are defined:
npm run
# Or view directly
cat package.json | jq .scriptsCommon typos:
# These are different!
npm run dev # vs
npm run start # vs
npm run serve
npm test # vs
npm run testNote: npm test, npm start are shortcuts.
Make sure you're in the right place:
pwd
ls package.json
# Check it's the right project
cat package.json | grep nameDefine the script:
{
"scripts": {
"start": "node index.js",
"dev": "nodemon index.js",
"build": "webpack",
"test": "jest"
}
}Run package binaries directly:
# Instead of npm run script
npx webpack
npx jest
npx eslint .Doesn't require script in package.json.
Find correct commands:
1. Read README.md
2. Check CONTRIBUTING.md
3. Look at other scripts for clues
4. Search project issues/discussions
Advanced notes
npm has built-in shortcuts: npm test (npm t), npm start, npm stop, npm restart. These don't require "run". Script names are case-sensitive. In monorepos, run scripts with -w flag for specific workspace. Consider using npm-run-all for running multiple scripts.
Frequently asked questions
- What does "npm ERR! Missing script:" mean?
- json's "scripts" object. If the script name isn't found, npm reports this error. This often happens with typos, when running commands from tutorials that assume certain scripts exist, or when switching between projects with different script configurations.
- How do I fix "npm ERR! Missing script:"?
- The "missing script" error occurs when you try to run an npm script that doesn't exist in package.json. Check your script name spelling or add the missing script to package.json.
- What causes "npm ERR! Missing script:"?
- Typo in script name Script not defined in package.json Running in wrong directory
- Is the "npm ERR! Missing script:" error serious?
- It is a low-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐npm Official Documentation
- ๐
- ๐