How to fix npm ERR! Missing script: "build" in npm
The "Missing script: build" error occurs when running npm run build but no build script is defined in package.json. Add the appropriate build command for your framework to resolve this.
Quick fix
Fixes npm ERR! Missing script: "build"
{
"scripts": {
"build": "react-scripts build"
}
}- Add build script for your framework
- Check available scripts
- Verify working directory
- Update deployment platform settings
{"scripts": {"build": "react-scripts build"}}npm ERR! Missing script: "build"
What this error means
This error indicates that npm cannot find a "build" script in your package.json file. Unlike `npm test` or `npm start`, `npm run build` is not a built-in npm command—it requires an explicit script definition. This commonly occurs when deploying to platforms like Netlify, Vercel, or Heroku that expect a build script, or when following tutorials that assume a build script exists. Not all projects need a build step—simple Node.js servers serving raw JavaScript don't require compilation.
Typical symptoms
- npm run build fails with "Missing script: build"
- Deployment to Netlify/Vercel/Heroku fails at build step
- CI/CD pipeline fails during build stage
- Following tutorial instructions that assume build script exists
- Error lists available scripts but "build" not among them
- Works locally but fails in production deployment
Common causes
- No "build" key defined in package.json scripts section
- Project does not require a build step (pure Node.js)
- Running from wrong directory that lacks package.json
- Script exists with different name (build:prod, build:dev)
- Duplicate scripts objects where second overrides first
- Using template/boilerplate without build configuration
How to fix "npm ERR! Missing script: "build""
Add the appropriate build script to package.json:
For React (Create React App):
{
"scripts": {
"build": "react-scripts build"
}
}For Vite:
{
"scripts": {
"build": "vite build"
}
}For Next.js:
{
"scripts": {
"build": "next build"
}
}For TypeScript:
{
"scripts": {
"build": "tsc"
}
}For Webpack:
{
"scripts": {
"build": "webpack --mode production"
}
}List all defined scripts to find the correct name:
# Show all available scripts
npm run
# Common alternative names:
npm run build:prod
npm run build:production
npm run compile
npm run bundleEnsure you're in the correct project directory:
# Check current location
pwd
# Verify package.json exists
cat package.json | head -20
# Navigate to project root if needed
cd /path/to/projectIf your project doesn't need a build step, update deployment settings:
Netlify (netlify.toml):
[build]
command = "echo 'No build required'"
publish = "public"Or set build command in platform UI to:
echo "No build step"If no build is needed but something expects the script:
{
"scripts": {
"build": "echo 'No build required' && exit 0"
}
}This satisfies CI/CD requirements while doing nothing.
If you have a build script but it fails, install dependencies:
# For React
npm install react-scripts
# For Vite
npm install vite
# For TypeScript
npm install typescript
# Then try building again
npm run buildAdvanced notes
Not all Node.js projects need a build step. If you're running a pure JavaScript server (Express, Fastify, etc.) without TypeScript or frontend assets, you may not need a build script at all.
For monorepos, ensure you're running the build command from the correct workspace directory, or use workspace-aware commands:
npm run build --workspace=packages/my-appDeployment platforms often let you customize the build command in their settings, which can be more flexible than modifying package.json.
Frequently asked questions
- What does "npm ERR! Missing script: "build"" mean?
- json file. Unlike npm test or npm start, npm run build is not a built-in npm command—it requires an explicit script definition. This commonly occurs when deploying to platforms like Netlify, Vercel, or Heroku that expect a build script, or when following tutorials that assume a build script exists.
- How do I fix "npm ERR! Missing script: "build""?
- The "Missing script: build" error occurs when running npm run build but no build script is defined in package.json. Add the appropriate build command for your framework to resolve this.
- What causes "npm ERR! Missing script: "build""?
- No "build" key defined in package.json scripts section Project does not require a build step (pure Node.js) Running from wrong directory that lacks package.json
- Is the "npm ERR! Missing script: "build"" 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
- 💬Stack Overflow: npm err missing script build(Stack Overflow)
- 🔗
- 📝