Hugo site building fine on production branch but not for preview on feature branch

Site name is https://mlnotary.com. The problem branch in particular is at Add per-page descriptions (fix ML-26) by tremby · Pull Request #1 · tremby/mlnotary.com · GitHub

The main branch builds fine. The only differences between main and this feature branch are

  • Some of the output markup is slightly different
  • For debugging this build I’ve added an ls command to the build script

When trying to build this branch for a preview, hugo is throwing an error:

4:34:18 PM: Netlify Build                                                 
4:34:18 PM: ────────────────────────────────────────────────────────────────
4:34:18 PM: ​
4:34:18 PM: ❯ Version
4:34:18 PM:   @netlify/build 29.31.0
4:34:18 PM: ​
4:34:18 PM: ❯ Flags
4:34:18 PM:   baseRelDir: true
4:34:18 PM:   buildId: 65750779d277270008e6be0e
4:34:18 PM:   deployId: 65750779d277270008e6be10
4:34:18 PM: ​
4:34:18 PM: ❯ Current directory
4:34:18 PM:   /opt/build/repo
4:34:18 PM: ​
4:34:18 PM: ❯ Config file
4:34:18 PM:   /opt/build/repo/netlify.toml
4:34:18 PM: ​
4:34:18 PM: ❯ Context
4:34:18 PM:   deploy-preview
4:34:18 PM: ​
4:34:18 PM: Build command from Netlify app                                
4:34:18 PM: ────────────────────────────────────────────────────────────────
4:34:18 PM: ​
4:34:18 PM: $ npm run build
4:34:18 PM: > mlnotary.com@1.0.0 build
4:34:18 PM: > npm run build:assets && ls && npm run build:pages
4:34:18 PM: > mlnotary.com@1.0.0 build:assets
4:34:18 PM: > gulp
4:34:19 PM: [00:34:19] Using gulpfile /opt/build/repo/gulpfile.js
4:34:19 PM: [00:34:19] Starting "default"...
4:34:19 PM: [00:34:19] Starting "js"...
4:34:19 PM: gulp js started
4:34:19 PM: [00:34:19] Finished "js" after 17 ms
4:34:19 PM: [00:34:19] Finished "default" after 19 ms
4:34:19 PM: archetypes
4:34:19 PM: content
4:34:19 PM: data
4:34:19 PM: generated
4:34:19 PM: gulpfile.js
4:34:19 PM: hugo.toml
4:34:19 PM: layouts
4:34:19 PM: netlify.toml
4:34:19 PM: node_modules
4:34:19 PM: package.json
4:34:19 PM: package-lock.json
4:34:19 PM: README.md
4:34:19 PM: src
4:34:19 PM: static
4:34:19 PM: > mlnotary.com@1.0.0 build:pages
4:34:19 PM: > hugo
4:34:19 PM: Error: Unable to locate config file or config directory. Perhaps you need to create a new site.
4:34:19 PM:        Run `hugo help new` for details.
4:34:19 PM: Total in 0 ms
4:34:19 PM: ​
4:34:19 PM: "build.command" failed                                        
4:34:19 PM: ────────────────────────────────────────────────────────────────
4:34:19 PM: ​
4:34:19 PM:   Error message
4:34:19 PM:   Command failed with exit code 255: npm run build (https://ntl.fyi/exit-code-255)
4:34:19 PM: ​
4:34:19 PM:   Error location
4:34:19 PM:   In Build command from Netlify app:
4:34:19 PM:   npm run build
4:34:19 PM: ​
4:34:19 PM:   Resolved config
4:34:19 PM:   build:
4:34:19 PM:     command: npm run build
4:34:19 PM:     commandOrigin: ui
4:34:19 PM:     environment:
4:34:19 PM:       - REVIEW_ID
4:34:19 PM:     publish: /opt/build/repo/public
4:34:19 PM:     publishOrigin: ui
4:34:19 PM:   redirects:
4:34:19 PM:     - force: true
4:34:19 PM:       from: /services/
4:34:19 PM:       status: 307
4:34:19 PM:       to: /services/real-estate-purchase-and-sale/
4:34:19 PM:   redirectsOrigin: config
4:34:19 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
4:34:19 PM: Failing build: Failed to build site
4:34:20 PM: Failed during stage "building site": Build script returned non-zero exit code: 2
4:34:20 PM: Finished processing build request in 17.424s

You can see where it runs the ls command that it’s in the right directory (repository root) and that a hugo.toml file exists there. Yet Error: Unable to locate config file or config directory. Perhaps you need to create a new site.

I tried a deployment on the main branch again just to sanity check, and that’s still building just fine.

What could be causing hugo not to find the config file on the feature branch preview?

You’re setting an updated version of Hugo for your production: Deploy details | Deploys | mlnotary | Netlify

The default version in Netlify’s build image doesn’t support hugo.toml. Changing that to config.toml would work OR use the updated version of Hugo.

Ah, thank you for pointing me in the right direction. I changed [context.production.environment] to [build.environment] in my netlify.toml and that did the trick.