Hugo build fails when pushing feature branch to netlify

I have a Hugo site (using version 0.63.2) hosted on Netlify. The site has been live for several months now with many deploys from both a master branch and staging branch and have never had a deploy fail.

I have a feature branch (feature-blog) that I am trying to push to Netlify. This feature branch adds a blog to the site (posts, category taxonomy, and Netlify cms). The Hugo version has not changed and the site builds with no issues on my local machine. Everything I have read with similar issues is solved by specifying the Hugo version in the Netlify config file, but I already have that in place and still getting failed deploys.

This is my local Hugo version: Hugo Static Site Generator v0.63.2/extended darwin/amd64

In Netlify Build Image Selection, I have Ubuntu Xenial 16.04 (default) selected

Here are the contents of my netlify.toml file:

[context.production.environment]
    HUGO_VERSION = "0.63.2"

[context.deploy-preview.environment]
    HUGO_VERSION = "0.63.2"

[context.branch-deploy]
    HUGO_VERSION = "0.63.2"
    command = "npm i && npm run gulp && hugo --environment=staging"

[context."feature-blog"]
    HUGO_VERSION = "0.63.2"
    command = "npm i && npm run gulp && hugo --environment=feature-blog"

I have a Hugo config file at /config/feature-blog/config.toml. The only thing in this file is
baseURL = “https://feature-blog--uprightpr.netlify.app/

Here is the deploy log:

9:36:48 PM: Build ready to start
9:36:51 PM: build-image version: 53b83b6bede2920f236b25b6f5a95334320dc849
9:36:51 PM: build-image tag: v3.6.0
9:36:51 PM: buildbot version: 7d7f8cd4cc19a5205bae0ea8df58feec103fed05
9:36:51 PM: Fetching cached dependencies
9:36:51 PM: Starting to download cache of 153.3MB
9:36:52 PM: Finished downloading cache in 1.216640617s
9:36:52 PM: Starting to extract cache
9:36:56 PM: Finished extracting cache in 3.581356387s
9:36:56 PM: Finished fetching cache in 4.884100904s
9:36:56 PM: Starting to prepare the repo for build
9:36:56 PM: Preparing Git Reference refs/heads/feature-blog
9:37:01 PM: Different build command detected, going to use the one specified in the Netlify configuration file: ‘npm i && npm run gulp && hugo --environment=feature-blog’ versus ‘npm i && npm run gulp && hugo --gc’ in the Netlify UI
9:37:02 PM: Starting build script
9:37:02 PM: Installing dependencies
9:37:02 PM: Python version set to 2.7
9:37:02 PM: Started restoring cached node version
9:37:04 PM: Finished restoring cached node version
9:37:05 PM: v12.18.0 is already installed.
9:37:05 PM: Now using node v12.18.0 (npm v6.14.4)
9:37:06 PM: Started restoring cached build plugins
9:37:06 PM: Finished restoring cached build plugins
9:37:06 PM: Attempting ruby version 2.7.1, read from environment
9:37:07 PM: Using ruby version 2.7.1
9:37:07 PM: Using PHP version 5.6
9:37:07 PM: Started restoring cached node modules
9:37:07 PM: Finished restoring cached node modules
9:37:08 PM: Started restoring cached go cache
9:37:08 PM: Finished restoring cached go cache
9:37:08 PM: go version go1.14.4 linux/amd64
9:37:08 PM: go version go1.14.4 linux/amd64
9:37:08 PM: Installing missing commands
9:37:08 PM: Verify run directory
9:37:09 PM: ​
9:37:09 PM: ────────────────────────────────────────────────────────────────
9:37:09 PM: Netlify Build
9:37:09 PM: ────────────────────────────────────────────────────────────────
9:37:09 PM: ​
9:37:09 PM: ❯ Version
9:37:09 PM: @netlify/build 8.0.5
9:37:09 PM: ​
9:37:09 PM: ❯ Flags
9:37:09 PM: deployId: 600251406faa7e0007dc489a
9:37:09 PM: mode: buildbot
9:37:09 PM: ​
9:37:09 PM: ❯ Current directory
9:37:09 PM: /opt/build/repo
9:37:09 PM: ​
9:37:09 PM: ❯ Config file
9:37:09 PM: /opt/build/repo/netlify.toml
9:37:09 PM: ​
9:37:09 PM: ❯ Context
9:37:09 PM: branch-deploy
9:37:09 PM: ​
9:37:09 PM: ────────────────────────────────────────────────────────────────
9:37:09 PM: 1. build.command from netlify.toml
9:37:09 PM: ────────────────────────────────────────────────────────────────
9:37:09 PM: ​
9:37:09 PM: $ npm i && npm run gulp && hugo --environment=feature-blog
9:37:13 PM: npm WARN upright@0.0.1 No repository field.
9:37:13 PM: npm WARN upright@0.0.1 No license field.
9:37:13 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/fsevents):
9:37:13 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {“os”:“darwin”,“arch”:“any”} (current: {“os”:“linux”,“arch”:“x64”})
9:37:13 PM: audited 512 packages in 2.778s
9:37:13 PM: 20 packages are looking for funding
9:37:13 PM: run npm fund for details
9:37:13 PM: found 2 low severity vulnerabilities
9:37:13 PM: run npm audit fix to fix them, or npm audit for details
9:37:13 PM: > upright@0.0.1 gulp /opt/build/repo
9:37:13 PM: > gulp
9:37:14 PM: [02:37:14] Using gulpfile /opt/build/repo/gulpfile.js
9:37:14 PM: [02:37:14] Starting ‘default’…
9:37:14 PM: [02:37:14] Starting ‘sass’…
9:37:15 PM: [02:37:15] Finished ‘sass’ after 1.24 s
9:37:15 PM: [02:37:15] Finished ‘default’ after 1.24 s
9:38:55 PM: Building sites … ERROR 2021/01/16 02:38:55 render of “taxonomy” failed: “/opt/build/repo/layouts/category/taxonomy.html:16:77”: execute of template failed: template: category/taxonomy.html:16:77: executing “main” at <.Page.Permalink>: can’t evaluate field Page in type hugolib.WeightedPagesERROR 2021/01/16 02:38:55 render of “section” failed: “/opt/build/repo/layouts/insights/list.html:15:55”: execute of template failed: template: insights/list.html:15:55: executing “main” at <.Page.Permalink>: can’t evaluate field Page in type hugolib.WeightedPagesERROR 2021/01/16 02:38:55 render of “taxonomy” failed: “/opt/build/repo/layouts/category/taxonomy.html:16:77”: execute of template failed: template: category/taxonomy.html:16:77: executing “main” at <.Page.Permalink>: can’t evaluate field Page in type hugolib.WeightedPagesERROR 2021/01/16 02:38:55 render of “taxonomy” failed: “/opt/build/repo/layouts/category/taxonomy.html:16:77”: execute of template failed: template: category/taxonomy.html:16:77: executing “main” at <.Page.Permalink>: can’t evaluate field Page in type hugolib.WeightedPagesTotal in 99804 ms
9:38:55 PM: Error: Error building site: failed to render pages: render of “taxonomy” failed: “/opt/build/repo/layouts/category/taxonomy.html:16:77”: execute of template failed: template: category/taxonomy.html:16:77: executing “main” at <.Page.Permalink>: can’t evaluate field Page in type hugolib.WeightedPages​
9:38:55 PM: ────────────────────────────────────────────────────────────────
9:38:55 PM: “build.command” failed
9:38:55 PM: ────────────────────────────────────────────────────────────────
9:38:55 PM: ​
9:38:55 PM: Error message
9:38:55 PM: Command failed with exit code 255: npm i && npm run gulp && hugo --environment=feature-blog
9:38:55 PM: ​
9:38:55 PM: Error location
9:38:55 PM: In build.command from netlify.toml:
9:38:55 PM: npm i && npm run gulp && hugo --environment=feature-blog
9:38:55 PM: ​
9:38:55 PM: Resolved config
9:38:55 PM: build:
9:38:55 PM: command: npm i && npm run gulp && hugo --environment=feature-blog
9:38:55 PM: commandOrigin: config
9:38:55 PM: publish: /opt/build/repo/public
9:38:56 PM: Caching artifacts
9:38:56 PM: Started saving node modules
9:38:56 PM: Finished saving node modules
9:38:56 PM: Started saving build plugins
9:38:56 PM: Finished saving build plugins
9:38:56 PM: Started saving pip cache
9:38:56 PM: Finished saving pip cache
9:38:56 PM: Started saving emacs cask dependencies
9:38:56 PM: Finished saving emacs cask dependencies
9:38:56 PM: Started saving maven dependencies
9:38:56 PM: Finished saving maven dependencies
9:38:56 PM: Started saving boot dependencies
9:38:56 PM: Finished saving boot dependencies
9:38:56 PM: Started saving rust rustup cache
9:38:56 PM: Finished saving rust rustup cache
9:38:56 PM: Started saving rust cargo bin cache
9:38:56 PM: Finished saving rust cargo bin cache
9:38:56 PM: Started saving go dependencies
9:38:56 PM: Finished saving go dependencies
9:38:56 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
9:38:56 PM: Failing build: Failed to build site
9:38:56 PM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2
9:38:56 PM: Finished processing build request in 2m5.276881582s

Any suggestions to help solve this are greatly appreciated.

I don’t think Hugo 0.63.2 is getting installed during your build. In my build, I always get a line saying:

11:34:54 PM: Using PHP version 5.6
11:34:54 PM: Installing Hugo 0.80.0
11:34:54 PM: Hugo Static Site Generator v0.80.0-792EF0F4/extended linux/amd64 BuildDate: 2020-12-31T13:46:18Z
11:34:54 PM: Started restoring cached go cache

which doesn’t exist in your build log.

Would you try setting an Environment Variable in Netlify Dashboard with name as HUGO_VERSION and value as 0.63.2? Then you won’t have to mention the version so many times in the config file.

If it still doesn’t fix it, I think I’d have to see the source of the taxonomy page. Maybe, you’re missing the context somewhere inside a range or something maybe. But since you say it builds fine locally, I’m guessing that’s not a problem.

You are correct. I added the HUGO_VERSION Environment Variable and tried to deploy again. It does install Hugo now, but I’m getting a new error about a circular loop in a shortcode. It references the file content/_index.md:1:1 which did not have any changes in this branch. No new shortcodes were added in this branch either. I also looked up the message “Command failed with exit code 255” and again it seems related to missing version and/or not using the extended version but its installing the exact same version I have locally.

Here is the new deploy log. Do you have any other ideas?
3:27:24 PM: Build ready to start
3:27:26 PM: build-image version: 53b83b6bede2920f236b25b6f5a95334320dc849
3:27:26 PM: build-image tag: v3.6.0
3:27:26 PM: buildbot version: 7d7f8cd4cc19a5205bae0ea8df58feec103fed05
3:27:26 PM: Fetching cached dependencies
3:27:26 PM: Starting to download cache of 153.3MB
3:27:28 PM: Finished downloading cache in 1.545881127s
3:27:28 PM: Starting to extract cache
3:27:32 PM: Finished extracting cache in 4.550414193s
3:27:32 PM: Finished fetching cache in 6.151479423s
3:27:32 PM: Starting to prepare the repo for build
3:27:33 PM: Preparing Git Reference refs/heads/feature-blog
3:27:38 PM: Different build command detected, going to use the one specified in the Netlify configuration file: ‘npm i && npm run gulp && hugo --environment=feature-blog’ versus ‘npm i && npm run gulp && hugo --gc’ in the Netlify UI
3:27:39 PM: Starting build script
3:27:39 PM: Installing dependencies
3:27:39 PM: Python version set to 2.7
3:27:39 PM: Started restoring cached node version
3:27:43 PM: Finished restoring cached node version
3:27:43 PM: v12.18.0 is already installed.
3:27:44 PM: Now using node v12.18.0 (npm v6.14.4)
3:27:44 PM: Started restoring cached build plugins
3:27:44 PM: Finished restoring cached build plugins
3:27:45 PM: Attempting ruby version 2.7.1, read from environment
3:27:46 PM: Using ruby version 2.7.1
3:27:47 PM: Using PHP version 5.6
3:27:47 PM: Started restoring cached node modules
3:27:47 PM: Finished restoring cached node modules
3:27:47 PM: Installing Hugo 0.63.2
3:27:47 PM: Hugo Static Site Generator v0.63.2-934EE21F/extended linux/amd64 BuildDate: 2020-01-27T12:20:42Z
3:27:47 PM: Started restoring cached go cache
3:27:47 PM: Finished restoring cached go cache
3:27:47 PM: go version go1.14.4 linux/amd64
3:27:47 PM: go version go1.14.4 linux/amd64
3:27:47 PM: Installing missing commands
3:27:47 PM: Verify run directory
3:27:50 PM: ​
3:27:50 PM: ────────────────────────────────────────────────────────────────
3:27:50 PM: Netlify Build
3:27:50 PM: ────────────────────────────────────────────────────────────────
3:27:50 PM: ​
3:27:50 PM: ❯ Version
3:27:50 PM: @netlify/build 8.0.5
3:27:50 PM: ​
3:27:50 PM: ❯ Flags
3:27:50 PM: deployId: 60034c2cede0ca0008a52d8c
3:27:50 PM: mode: buildbot
3:27:50 PM: ​
3:27:50 PM: ❯ Current directory
3:27:50 PM: /opt/build/repo
3:27:50 PM: ​
3:27:50 PM: ❯ Config file
3:27:50 PM: /opt/build/repo/netlify.toml
3:27:50 PM: ​
3:27:50 PM: ❯ Context
3:27:50 PM: branch-deploy
3:27:50 PM: ​
3:27:50 PM: ────────────────────────────────────────────────────────────────
3:27:50 PM: 1. build.command from netlify.toml
3:27:50 PM: ────────────────────────────────────────────────────────────────
3:27:50 PM: ​
3:27:50 PM: $ npm i && npm run gulp && hugo --environment=feature-blog
3:27:54 PM: npm WARN upright@0.0.1 No repository field.
3:27:54 PM: npm WARN upright@0.0.1 No license field.
3:27:54 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/fsevents):
3:27:54 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {“os”:“darwin”,“arch”:“any”} (current: {“os”:“linux”,“arch”:“x64”})
3:27:54 PM: audited 512 packages in 4.046s
3:27:55 PM: 20 packages are looking for funding
3:27:55 PM: run npm fund for details
3:27:55 PM: found 2 low severity vulnerabilities
3:27:55 PM: run npm audit fix to fix them, or npm audit for details
3:27:55 PM: > upright@0.0.1 gulp /opt/build/repo
3:27:55 PM: > gulp
3:27:56 PM: [20:27:56] Using gulpfile /opt/build/repo/gulpfile.js
3:27:56 PM: [20:27:56] Starting ‘default’…
3:27:56 PM: [20:27:56] Starting ‘sass’…
3:27:58 PM: [20:27:58] Finished ‘sass’ after 1.58 s
3:27:58 PM: [20:27:58] Finished ‘default’ after 1.58 s
3:30:22 PM: Building sites … Total in 144329 ms
3:30:22 PM: Error: Error building site: “/opt/build/repo/content/_index.md:1:1”: timed out initializing value. This is most likely a circular loop in a shortcode
3:30:22 PM: ​
3:30:22 PM: ────────────────────────────────────────────────────────────────
3:30:22 PM: “build.command” failed
3:30:22 PM: ────────────────────────────────────────────────────────────────
3:30:22 PM: ​
3:30:22 PM: Error message
3:30:22 PM: Command failed with exit code 255: npm i && npm run gulp && hugo --environment=feature-blog
3:30:22 PM: ​
3:30:22 PM: Error location
3:30:22 PM: In build.command from netlify.toml:
3:30:22 PM: npm i && npm run gulp && hugo --environment=feature-blog
3:30:22 PM: ​
3:30:22 PM: Resolved config
3:30:22 PM: build:
3:30:22 PM: command: npm i && npm run gulp && hugo --environment=feature-blog
3:30:22 PM: commandOrigin: config
3:30:22 PM: environment:
3:30:22 PM: - HUGO_VERSION
3:30:22 PM: publish: /opt/build/repo/public
3:30:23 PM: Caching artifacts
3:30:23 PM: Started saving node modules
3:30:23 PM: Finished saving node modules
3:30:23 PM: Started saving build plugins
3:30:23 PM: Finished saving build plugins
3:30:23 PM: Started saving pip cache
3:30:23 PM: Finished saving pip cache
3:30:23 PM: Started saving emacs cask dependencies
3:30:23 PM: Finished saving emacs cask dependencies
3:30:23 PM: Started saving maven dependencies
3:30:23 PM: Finished saving maven dependencies
3:30:23 PM: Started saving boot dependencies
3:30:23 PM: Finished saving boot dependencies
3:30:23 PM: Started saving rust rustup cache
3:30:23 PM: Finished saving rust rustup cache
3:30:23 PM: Started saving rust cargo bin cache
3:30:23 PM: Finished saving rust cargo bin cache
3:30:23 PM: Started saving go dependencies
3:30:23 PM: Finished saving go dependencies
3:30:23 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
3:30:23 PM: Failing build: Failed to build site
3:30:23 PM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2
3:30:23 PM: Finished processing build request in 2m57.088626629s

This might happen if you’re using image processing. Is that the case?

If it is, it’s useful to commit the resources/_gen folder from the local to the repo. Doing so will help Hugo not have to process images again, and thus the timeout won’t be triggered.

A loop can also happen when you’re trying to access non-shortcode variables in a shortcode using some hacky way.

There’s an interesting thread regarding the same on Hugo’s forums: Shortcode content loop hugo does not finish building the site - support - HUGO

Try one of that, but if nothing works, without the shortcode’s source, it’s not possible to guess.

Yep, it seems the image processing was the issue. I had ~30 test posts with featured images for development purposes; I removed them and the build completed successfully. Thank you so much for your help!

As for the resources/_gen directory, do you know if that directory is rebuilt with every push, or does it only generate any new files it needs in a deploy? I’d like to avoid tracking it if possible but maybe I can start with just the images directory for the blog section if it rebuilds on every deploy.

Thanks again!

I think it’s rebuilt with every build. However I’ve not used Hugo’s image processing (I prefer optimising the images manually), so I can’t say for sure. I said it’s rebuilt on every push because of the fact that there exists a Netlify build plugin that claims to persist this processed image cache of Hugo.