The "Missing script: dev" error occurs when running npm run dev but no dev script is defined in package.json. Add a development server script appropriate for your framework to resolve this.
This error means npm cannot find a "dev" script in your package.json file. The `dev` script is a common convention for starting a development server with features like hot reloading, but it's not a built-in npm command—it must be explicitly defined. This typically happens when following framework documentation that assumes a dev script exists, or when cloning a project that uses different script naming conventions (like "start" instead of "dev").
Add the appropriate dev script to package.json:
For Vite:
{
"scripts": {
"dev": "vite"
}
}For Next.js:
{
"scripts": {
"dev": "next dev"
}
}For Node.js with nodemon:
{
"scripts": {
"dev": "nodemon index.js"
}
}For Webpack Dev Server:
{
"scripts": {
"dev": "webpack serve --mode development"
}
}For Create React App (uses start instead):
{
"scripts": {
"dev": "react-scripts start"
}
}List available scripts—your project may use a different name:
# Show all scripts
npm run
# Common alternatives to try:
npm start
npm run serve
npm run develop
npm run watchEnsure you're in the project root:
# Check location
pwd
# Verify package.json exists
ls package.json
# Check scripts section
cat package.json | grep -A 20 '"scripts"'The dev script may require tools that aren't installed:
# Install dependencies first
npm install
# Common dev tools:
npm install --save-dev nodemon
npm install --save-dev vite
npm install --save-dev webpack-dev-serverAs a workaround, run the development tool directly:
# Vite
npx vite
# Next.js
npx next dev
# Nodemon
npx nodemon index.js
# Webpack
npx webpack serveEnsure only one scripts section exists in package.json:
// Wrong - second scripts overrides first
{
"scripts": { "dev": "vite" },
"scripts": { "build": "vite build" }
}
// Correct - single scripts object
{
"scripts": {
"dev": "vite",
"build": "vite build"
}
}The naming convention varies by framework and community preference:
- Vite/Next.js/Nuxt: Typically use "dev"
- Create React App: Uses "start" for development
- Express/Node.js: Often uses "start" or "dev" with nodemon
When cloning repositories, always check the README or package.json for the correct development command. Some projects document this in a "Getting Started" or "Development" section.
In monorepos, you may need to run dev scripts from specific workspace directories or use workspace-aware commands:
npm run dev --workspace=packages/frontendnpm 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