npm ERR! missing script: ...
The npm ERR! missing script error means the script is not defined in package.json. Fix it by adding it to the scripts section or checking for typos.
What It Means
npm looks up the script name in package.json under the "scripts" object. If the key doesn’t exist, npm exits with this error. It shows the exact script name you typed, so a typo is immediately visible. The error includes Did you mean this? suggestions if npm finds similar script names.
Why It Happens
- You typed the script name wrong (e.g.,
npm run stratinstead ofnpm run start). - The project’s
package.jsondoesn’t define that script at all. - You’re in the wrong directory — you might be running the command outside the project root.
- The project expects a different package manager (e.g.,
yarn devvsnpm run dev). - The
package.jsonis malformed (JSON syntax error).
How to Fix It
1. Check the available scripts
npm runThis prints all available scripts defined in package.json. Compare the output with the script name you’re trying to run.
2. Check package.json directly
cat package.json | grep -A 20 '"scripts"'Or view the full scripts section:
node -e "console.log(JSON.parse(require('fs').readFileSync('package.json','utf8')).scripts)"3. Add the missing script
Edit package.json and add the missing script under the "scripts" field:
"scripts": {
"dev": "vite",
"build": "vite build",
"start": "node server.js"
}Then run:
npm run dev4. Check your working directory
pwd
ls package.jsonIf package.json doesn’t exist, you’re in the wrong folder or the project hasn’t been initialized. Run npm init -y to create one.
5. Restore a missing package.json
If the file was accidentally deleted, recover it from version control or recreate it:
git checkout package.json # if using git
npm init -y # create a new one (lose custom scripts)Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro