Netlify Build Fails: Command Not Found – Fix Now
Your Netlify build fails with 'command not found'. I'll show you the quick fix and why it happens. No fluff.
You're looking at a failed Netlify build, and the log says 'command not found'. I know this error is infuriating.
I've seen this hundreds of times. The fix is usually simple: your Netlify build environment doesn't know where your command lives. Let's get it sorted.
The Quick Fix
Open your netlify.toml file or your Netlify deploy settings. The problem is almost always in the build command. Here's what to check:
- Make sure your build command uses the full path or the correct package manager. For example, if you use
npmcommands, writenpm run build— not justrun build. - If you're using Yarn, write
yarn build. Netlify's default environment doesn't always have Yarn on the path unless you set it. - Set your Node.js version in
netlify.toml. Like this:
[build]
command = "npm run build"
publish = "dist"
[build.environment]
NODE_VERSION = "18"
If you're still stuck, try changing your build command to use npx for local tools. For instance, npx vue-cli-service build instead of vue-cli-service build.
Why This Happens
Netlify runs your build in a clean Linux container. It has Node.js, npm, and a few other tools pre-installed. But if your project expects a specific package manager (like Yarn or pnpm) or a global CLI tool (like Gatsby, Hugo, or React Scripts), Netlify won't have them unless you tell it.
The 'command not found' error means the shell can't find the executable. This happens because:
- Your build command references a global tool that isn't installed in the build environment.
- Your
package.jsonhas scripts that call commands not in thePATH. - You're using Yarn 2+ (Berry) which uses
yarn dlxinstead ofnpx, and Netlify doesn't set it up automatically.
Less Common Variations
Sometimes the fix isn't in the build command. Here are a few real-world gotchas:
- Monorepo issues: If your
netlify.tomlpoints to a subdirectory, the command might run from the wrong folder. Setbasein the build section:base = "packages/frontend". - Private packages: If your build needs a private npm package, you need an
.npmrcfile with an auth token. Netlify won't ask for it — you must add it as an environment variable. - Hugo/Static site generators: You must set the
HUGO_VERSIONenvironment variable, or Netlify uses an old version that might not work with your project. - Python projects: Netlify supports Python builds, but you need to specify the runtime and install dependencies manually in the build command, like
pip install -r requirements.txt.
How to Stop This Forever
Once you fix it, here's how to avoid hitting it again:
- Always pin your Node version in
netlify.toml. Don't rely on the default — it changes over time and breaks builds. - Test your build locally with the Netlify CLI. Run
netlify buildin your terminal to see if it works before you push. - Use
npxfor local CLI tools that are indevDependencies. This avoids version conflicts and missing tools. - Check your build logs the first time after a fix. Netlify shows the exact command it runs. If it looks wrong, you'll see it right there.
I've seen this error pop up after updating a project's package.json, switching package managers, or moving to a new Node major version. The fix is almost always in the build settings or environment variables. Now you know exactly where to look.
Was this solution helpful?