How to configure build settings on Netlify
Link your Git repo in Netlify UI, navigate to Build settings, configure base directory (e.g., /frontend), build command (e.g., npm run build), and publish directory (e.g., dist); save to trigger deploy. Use netlify.toml in repo root for overrides like context-specific commands. Test locally with netlify build --debug to mimic production.
Prerequisites
- Netlify account (free tier sufficient)
- Git repository (GitHub, GitLab, or Bitbucket) with site code
- Knowledge of your project's build tool (e.g., npm, or none for static HTML)
- Optional: Netlify CLI installed via
npm install -g netlify-cli
Step-by-Step Instructions
Log in and select your site
Navigate to Build settings
Set the base directory
/frontend for monorepos). Leave blank for repo root. Netlify uses this to check for package.json or .nvmrc and perform caching.Configure the build command
npm run build, nuxt build for Nuxt 3, or leave blank for static sites). Defaults to none, assuming static files in publish directory.Specify the publish directory
dist, build, public). For simple static sites with just index.html, use . or public. This must be specified.Set package directory (monorepos)
/packages/website). If unset, Netlify searches base/root for netlify.toml. Defaults to auto-detected.Adjust advanced settings
Save and verify deploy
Use netlify.toml for overrides
netlify.toml in repo root (or base directory) to override UI. Example:
[build]
command = "npm run build"
base = "/frontend"
publish = "dist"
[context.production.environment]
NODE_VERSION = "20"Commit and push; file takes precedence.Test locally with Netlify CLI
npm install netlify-cli -g. Run netlify init or netlify linked to link site. Test with netlify build --debug (mimics Netlify environment, uses set env vars).Common Issues & Troubleshooting
"Failed during stage 'building site': Build script returned non-zero exit code" or "npm run build failed"
Verify build command is correct (e.g., npm run build, not npm install). Check logs in Deploys tab, test locally with netlify build --debug, ensure dependencies match.
Build skips or uses wrong paths in monorepos
Confirm base directory and package directory point to correct subfolders (e.g., /frontend). Use netlify.toml with explicit base and publish.
Node/Ruby version mismatch causing failures
Set NODE_VERSION (e.g., "20") as environment variable in UI or netlify.toml under [context.production.environment]. Select specific build image if needed.
Static site deploys blank or 404s
Set publish directory to . or public, leave build command blank. Ensure index.html is in root or specified folder.
Environment variables not available during build
Add vars in UI under Project configuration > Build & deploy > Environment. Test with netlify build after netlify env:set.