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., <code>npm run build</code>), and publish directory (e.g., dist); save to trigger deploy. Use <code>netlify.toml</code> in repo root for overrides like context-specific commands. Test locally with <code>netlify build --debug</code> 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 <code>npm install -g netlify-cli</code>
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 <strong>build command</strong> is correct (e.g., <code>npm run build</code>, not <code>npm install</code>). Check logs in <strong>Deploys</strong> tab, test locally with <code>netlify build --debug</code>, ensure dependencies match.
Build skips or uses wrong paths in monorepos
Confirm <strong>base directory</strong> and <strong>package directory</strong> point to correct subfolders (e.g., <code>/frontend</code>). Use <code>netlify.toml</code> with explicit <code>base</code> and <code>publish</code>.
Node/Ruby version mismatch causing failures
Set <code>NODE_VERSION</code> (e.g., "20") as environment variable in UI or <code>netlify.toml</code> under <code>[context.production.environment]</code>. Select specific <strong>build image</strong> if needed.
Static site deploys blank or 404s
Set <strong>publish directory</strong> to <code>.</code> or <code>public</code>, leave <strong>build command</strong> blank. Ensure <code>index.html</code> is in root or specified folder.
Environment variables not available during build
Add vars in UI under <strong>Project configuration > Build & deploy > Environment</strong>. Test with <code>netlify build</code> after <code>netlify env:set</code>.