The Missing script error occurs when you try to run an npm script that doesn't exist in your package.json. Verify the script name, check you're in the correct directory, and ensure your package.json has the required scripts section.
This error means npm couldn't find the script you're trying to run in your package.json file. When you execute `npm run dev` or `npm start`, npm looks for a matching entry in the "scripts" section of package.json. If there's no match, you get this error. The error is straightforward but can occur for several reasons: you might be in the wrong directory, the script might have a different name than expected, or the package.json might not have been properly initialized. This is one of the most common npm errors, especially for developers new to a project or when following tutorials that assume certain scripts exist.
Run npm run without any arguments to see all available scripts:
npm runThis shows the complete list of scripts defined in your package.json, helping you find the correct name.
Make sure you're in the project root where package.json is located:
ls package.jsonIf the file doesn't exist, navigate to the correct directory:
cd /path/to/your/projectOpen package.json and look for the scripts section:
{
"scripts": {
"start": "node index.js",
"dev": "vite",
"build": "vite build",
"test": "jest"
}
}If your desired script is missing, add it with the appropriate command.
Common typos include:
- npm run bulid instead of npm run build
- npm run dve instead of npm run dev
- Extra spaces in the command
Script names are case-sensitive, so npm run Dev won't find a script named dev.
If the script genuinely doesn't exist, add it to package.json:
{
"scripts": {
"dev": "next dev",
"start": "next start",
"build": "next build"
}
}The command depends on your framework (Vite, Next.js, Create React App, etc.).
If there's no package.json at all, create one:
npm init -yThen add your scripts manually or install your framework, which will set up appropriate scripts.
Different frameworks use different default script names. Create React App uses start for development, while Vite uses dev. Next.js uses dev for development and start for production. Always check the framework's documentation for expected script names.
The npm start command is special—it runs the "start" script without needing run (unlike npm run build). Similarly, npm test runs the "test" script directly.
In monorepos, you might need to run scripts from a specific workspace:
npm run dev --workspace=packages/frontendOr from the workspace directory itself. Check your monorepo configuration for the correct approach.
npm error code ENOENT npm error syscall spawn git npm error path git npm error errno -4058 npm error enoent An unknown git error occurred
How to fix "spawn git ENOENT" in npm
npm error code E401 npm error Incorrect or missing password.
How to fix 'E401 Unable to authenticate' errors with npm private registries
npm notice access token expired or revoked. Please try logging in again.
Token has expired - npm authentication failure
npm ERR! code EAI_AGAIN
How to fix "EAI_AGAIN" in npm
npm error code E403 npm error 403 Forbidden - PUT https://registry.npmjs.org/<package>
How to fix 'E403 Forbidden' error in npm