Deployment of Hugo site fails: flag provided but not defined: -modcacherw

Hi,

I have two Hugo sites on Netlify. Both use Hugo Modules to include a theme.
One site (christophberger.netlify.app) builds without issues, the other one (appliedgo.netlify.app) reproducibly fails with an error:

9:19:28 AM: build.command from netlify.toml                               
9:19:28 AM: ────────────────────────────────────────────────────────────────
9:19:28 AM: ​
9:19:28 AM: $ hugo --gc --minify
9:19:28 AM: flag provided but not defined: -modcacherw
9:19:28 AM: usage: go mod download [-json] [modules]
9:19:28 AM: Run 'go help mod download' for details.
9:19:28 AM: Total in 8 ms
9:19:28 AM: Error: failed to load modules: failed to download modules: failed to execute 'go [mod download -modcacherw]': failed to execute binary "go" with args [mod download -modcacherw]: flag provided but not defined: -modcacherw
9:19:28 AM: usage: go mod download [-json] [modules]
9:19:28 AM: Run 'go help mod download' for details.

Full log:

9:18:50 AM: Build ready to start
9:19:02 AM: build-image version: 3d3c7e8b4321e2c1a54a2c4584fb46ba742b1630 (focal)
9:19:02 AM: buildbot version: 6e230d07ad2817029f7ba1516ca5c5a8371963f3
9:19:02 AM: Fetching cached dependencies
9:19:02 AM: Failed to fetch cache, continuing with build
9:19:02 AM: Starting to prepare the repo for build
9:19:03 AM: No cached dependencies found. Cloning fresh repo
9:19:03 AM: git clone --filter=blob:none https://github.com/christophberger/appliedgo
9:19:04 AM: Preparing Git Reference refs/heads/main
9:19:07 AM: Custom build path detected. Proceeding with the specified path: ''
9:19:07 AM: Custom publish path detected. Proceeding with the specified path: 'public'
9:19:07 AM: Custom build command detected. Proceeding with the specified command: 'hugo --gc --minify'
9:19:08 AM: Starting to install dependencies
9:19:08 AM: Python version set to 3.8
9:19:09 AM: Attempting Ruby version 2.6.2, read from environment
9:19:09 AM: Required ruby-2.6.2 is not installed - installing.
9:19:09 AM: Searching for binary rubies, this might take some time.
9:19:09 AM: Found remote file https://rvm_io.global.ssl.fastly.net/binaries/ubuntu/20.04/x86_64/ruby-2.6.2.tar.bz2
9:19:09 AM: Checking requirements for ubuntu.
9:19:10 AM: Requirements installation successful.
9:19:10 AM: ruby-2.6.2 - #configure
9:19:10 AM: ruby-2.6.2 - #download
9:19:10 AM: ruby-2.6.2 - #validate archive
9:19:13 AM: ruby-2.6.2 - #extract
9:19:15 AM: ruby-2.6.2 - #validate binary
9:19:15 AM: ruby-2.6.2 - #setup
9:19:15 AM: ruby-2.6.2 - #gemset created /opt/buildhome/.rvm/gems/ruby-2.6.2@global
9:19:15 AM: ruby-2.6.2 - #importing gemset /opt/buildhome/.rvm/gemsets/global.gems........................................
9:19:16 AM: ruby-2.6.2 - #generating global wrappers........
9:19:16 AM: ruby-2.6.2 - #gemset created /opt/buildhome/.rvm/gems/ruby-2.6.2
9:19:16 AM: ruby-2.6.2 - #importing gemsetfile /opt/buildhome/.rvm/gemsets/default.gems evaluated to empty gem list
9:19:16 AM: ruby-2.6.2 - #generating default wrappers........
9:19:16 AM: Using /opt/buildhome/.rvm/gems/ruby-2.6.2
9:19:16 AM: Using Ruby version 2.6.2
9:19:17 AM: Started restoring cached go cache
9:19:17 AM: Finished restoring cached go cache
9:19:17 AM: Installing Go version 1.12 (requested 1.12)
9:19:21 AM: go version go1.12 linux/amd64
9:19:21 AM: Using PHP version 8.0
9:19:21 AM: Installing Hugo 0.126.0
9:19:22 AM: hugo v0.126.0-32c967551be308fbd14e5f0dfba0ff50a60e7f5e+extended linux/amd64 BuildDate=2024-05-14T13:24:11Z VendorInfo=gohugoio
9:19:24 AM: Downloading and installing node v10.24.1...
9:19:24 AM: Downloading https://nodejs.org/dist/v10.24.1/node-v10.24.1-linux-x64.tar.xz...
9:19:24 AM: Computing checksum with sha256sum
9:19:24 AM: Checksums matched!
9:19:25 AM: Now using node v10.24.1 (npm v6.14.12)
9:19:25 AM: Started restoring cached build plugins
9:19:25 AM: Finished restoring cached build plugins
9:19:25 AM: Successfully installed dependencies
9:19:25 AM: Starting build script
9:19:26 AM: Detected 0 framework(s)
9:19:26 AM: Section completed: initializing
9:19:28 AM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
9:19:28 AM: ​
9:19:28 AM: Netlify Build                                                 
9:19:28 AM: ────────────────────────────────────────────────────────────────
9:19:28 AM: ​
9:19:28 AM: ❯ Version
9:19:28 AM:   @netlify/build 29.45.0
9:19:28 AM: ​
9:19:28 AM: ❯ Flags
9:19:28 AM:   baseRelDir: false
9:19:28 AM:   buildId: 665ebfd945108900080015c2
9:19:28 AM:   deployId: 665ebfd945108900080015c4
9:19:28 AM: ​
9:19:28 AM: ❯ Current directory
9:19:28 AM:   /opt/build/repo
9:19:28 AM: ​
9:19:28 AM: ❯ Config file
9:19:28 AM:   /opt/build/repo/netlify.toml
9:19:28 AM: ​
9:19:28 AM: ❯ Context
9:19:28 AM:   production
9:19:28 AM: ​
9:19:28 AM: build.command from netlify.toml                               
9:19:28 AM: ────────────────────────────────────────────────────────────────
9:19:28 AM: ​
9:19:28 AM: $ hugo --gc --minify
9:19:28 AM: flag provided but not defined: -modcacherw
9:19:28 AM: usage: go mod download [-json] [modules]
9:19:28 AM: Run 'go help mod download' for details.
9:19:28 AM: Total in 8 ms
9:19:28 AM: Error: failed to load modules: failed to download modules: failed to execute 'go [mod download -modcacherw]': failed to execute binary "go" with args [mod download -modcacherw]: flag provided but not defined: -modcacherw
9:19:28 AM: usage: go mod download [-json] [modules]
9:19:28 AM: Run 'go help mod download' for details.
9:19:28 AM:  *errors.errorString
9:19:28 AM: ​
9:19:28 AM: "build.command" failed                                        
9:19:28 AM: ────────────────────────────────────────────────────────────────
9:19:28 AM: ​
9:19:28 AM:   Error message
9:19:28 AM:   Command failed with exit code 1: hugo --gc --minify (https://ntl.fyi/exit-code-1)
9:19:28 AM: ​
9:19:28 AM:   Error location
9:19:28 AM:   In build.command from netlify.toml:
9:19:28 AM:   hugo --gc --minify
9:19:28 AM: ​
9:19:28 AM:   Resolved config
9:19:28 AM:   build:
9:19:28 AM:     base: /opt/build/repo
9:19:28 AM:     command: hugo --gc --minify
9:19:28 AM:     commandOrigin: config
9:19:28 AM:     environment:
9:19:28 AM:       - HUGO_ENVIRONMENT
9:19:28 AM:       - HUGO_VERSION
9:19:28 AM:       - TZ
9:19:28 AM:     publish: /opt/build/repo/public
9:19:28 AM:     publishOrigin: config
9:19:28 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
9:19:28 AM: Failing build: Failed to build site
9:19:28 AM: Finished processing build request in 26.174s

My netlify.toml for both sites:

[build.environment]
HUGO_VERSION = "0.126.3"
TZ = "Europe/Berlin"

[build]
publish = "public"
command = "hugo --gc --minify"

My go.mod file for Hugo:

module github.com/christophberger/appliedgo

go 1.22

require github.com/christophberger/hugo-theme-appliedgo v0.3.1 // indirect

appliedgo.netlify.app was previously deployed as a pre-generated static site, that’s why a published site exists already. But since I switched to hugo deployment, all deploys failed so far.

Is this a known issue?
If not, how can I troubleshoot this error further?

Found the reason, it is well hidden in the log output and the docs:

9:19:17 AM: Installing Go version 1.12 (requested 1.12)

That’s what the docs say:

During your project’s first build, we pin a version of Node, Ruby, Go, and Yarn that matches the default version installed on the build image. These pinned versions are stored in your project’s repository object, associating those pinned versions with your project’s Git repository. This ensures your project’s software versions will not be affected if the build image’s defaults change.

(Build configuration overview | Netlify Docs)

<rant>Considering that I cannot select a build image newer than Ubuntu 20.4 (four years old!), it’s no wonder that I get such an antique version of Go that does not know the -modcacherw flag.</rant>

With this information, the now obvious solution is to set GO_VERSION to something sane.

1 Like

Hot tip: Set GO_VERSION to “1.x” to always use the latest Go toolchain. No more fiddling with Go versions, and you should always use the latest Go version anyway, for security reasons alone.

And you don’t need to create a .go_version file. The Go version can as well be set in netlify.toml, even though the docs do not mention this circumstance.

1 Like