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.
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.
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