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.
Fixes npm ERR! Missing script: "build"
{
"scripts": {
"build": "react-scripts build"
}
}{"scripts": {"build": "react-scripts build"}}npm ERR! Missing script: "build"
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.
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 buildNot 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.