npm ERR! missing script — how to fix
Quick Answer
# See which scripts actually exist
npm run
# Open package.json and check the exact script name
# Example: use "build", not "Build"
npm run build
# If the script does not exist, add it under "scripts"
{
"scripts": {
"build": "vite build"
}
}
When this happens
npm ERR! Missing script: "build"
npm ERR!
npm ERR! To see a list of scripts, run:
npm ERR! npm run
npm could not find the script name you asked to run. This usually means the script is missing from package.json, the name is misspelled, or you are in the wrong package directory.
Common causes
List available scripts first
npm run
# Shows every script under package.json -> scripts
Wrong directory or wrong workspace package
In a monorepo, the root package may not define the same scripts as the app package you intended to run.
# Run from the correct package
cd apps/web
npm run build
# Or target a workspace explicitly
npm run build --workspace web
Script name is case-sensitive
# package.json
{
"scripts": {
"build": "vite build"
}
}
# Correct
npm run build
# Wrong
npm run Build
Add the script if it does not exist yet
{
"scripts": {
"dev": "vite",
"build": "vite build",
"test": "vitest run"
}
}
Related