Build of Hugo site can't find theme with module not found error

Hello,

I have followed the official Netlify documentation for deploying a Hugo static site, including the proper use of Git submodules for my site’s theme.

However, when deploying the site from my Git repository to Netlify, the build fails with an error saying:

Error: module “hugo-theme-monochrome” not found; either add it as a Hugo Module or store it in “/opt/build/repo/themes”.: module does not exist

hugo-theme-monochrome is the name of the theme from here, which is also specified in my Hugo site’s config.toml.

I can’t figure out why Netlify’s build process is failing to pull in the theme’s submodule.

I tried using netlify.toml in my repository and also without where I specify build settings in my Netlify site’s build and deploy settings page. In both cases, the settings are:

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

I also tried specifying the Hugo version but that didn’t make a difference.

Here’s a representative build log:

4:20:20 PM: build-image version: d7b3813f01c06610bc1723ff1b22446513ee7941 (focal)
4:20:20 PM: build-image tag: v4.14.3
4:20:20 PM: buildbot version: be0925a1b4e8f8d2c5a767f3e0decf8856cad273
4:20:20 PM: Building without cache
4:20:20 PM: Starting to prepare the repo for build
4:20:21 PM: No cached dependencies found. Cloning fresh repo
4:20:21 PM: git clone git@gitlab.com:penyuan/personal-site
4:20:22 PM: Preparing Git Reference refs/heads/main
4:20:23 PM: Parsing package.json dependencies
4:20:24 PM: Starting build script
4:20:24 PM: Installing dependencies
4:20:24 PM: Python version set to 2.7
4:20:24 PM: Downloading and installing node v16.18.1...
4:20:24 PM: Downloading https://nodejs.org/dist/v16.18.1/node-v16.18.1-linux-x64.tar.xz...
4:20:25 PM: Computing checksum with sha256sum
4:20:25 PM: Checksums matched!
4:20:27 PM: Now using node v16.18.1 (npm v8.19.2)
4:20:27 PM: Enabling node corepack
4:20:27 PM: Started restoring cached build plugins
4:20:27 PM: Finished restoring cached build plugins
4:20:27 PM: Attempting ruby version 2.7.2, read from environment
4:20:28 PM: Using ruby version 2.7.2
4:20:28 PM: Using PHP version 8.0
4:20:28 PM: Started restoring cached go cache
4:20:28 PM: Finished restoring cached go cache
4:20:28 PM: Installing Go version 1.17 (requested 1.17)
4:20:34 PM: unset GOOS;
4:20:34 PM: unset GOARCH;
4:20:34 PM: export GOROOT='/opt/buildhome/.gimme/versions/go1.17.linux.amd64';
4:20:34 PM: export PATH="/opt/buildhome/.gimme/versions/go1.17.linux.amd64/bin:${PATH}";
4:20:34 PM: go version >&2;
4:20:34 PM: export GIMME_ENV="/opt/buildhome/.gimme/env/go1.17.linux.amd64.env"
4:20:34 PM: go version go1.17 linux/amd64
4:20:34 PM: Detected 2 framework(s)
4:20:35 PM: null at version null
4:20:35 PM: null at version null
4:20:35 PM: Installing missing commands
4:20:35 PM: Verify run directory
4:20:36 PM: ​
4:20:36 PM: ────────────────────────────────────────────────────────────────
4:20:36 PM:   Netlify Build                                                 
4:20:36 PM: ────────────────────────────────────────────────────────────────
4:20:36 PM: ​
4:20:36 PM: ❯ Version
4:20:36 PM:   @netlify/build 28.1.13
4:20:36 PM: ​
4:20:36 PM: ❯ Flags
4:20:36 PM:   baseRelDir: true
4:20:36 PM:   buildId: 636e7642a5d32704259bd8da
4:20:36 PM:   deployId: 636e7642a5d32704259bd8dc
4:20:36 PM: ​
4:20:36 PM: ❯ Current directory
4:20:36 PM:   /opt/build/repo
4:20:36 PM: ​
4:20:36 PM: ❯ Config file
4:20:36 PM:   No config file was defined: using default values.
4:20:36 PM: ​
4:20:36 PM: ❯ Context
4:20:36 PM:   production
4:20:36 PM: ​
4:20:36 PM: ────────────────────────────────────────────────────────────────
4:20:36 PM:   1. Build command from Netlify app                             
4:20:36 PM: ────────────────────────────────────────────────────────────────
4:20:36 PM: ​
4:20:36 PM: $ hugo --gc --minify
4:20:36 PM: Error: module "hugo-theme-monochrome" not found; either add it as a Hugo Module or store it in "/opt/build/repo/themes".: module does not exist
4:20:36 PM: Total in 0 ms
4:20:36 PM: ​
4:20:36 PM: ────────────────────────────────────────────────────────────────
4:20:36 PM:   "build.command" failed                                        
4:20:36 PM: ────────────────────────────────────────────────────────────────
4:20:36 PM: ​
4:20:36 PM:   Error message
4:20:36 PM:   Command failed with exit code 255: hugo --gc --minify
4:20:36 PM: ​
4:20:36 PM:   Error location
4:20:36 PM:   In Build command from Netlify app:
4:20:36 PM:   hugo --gc --minify
4:20:36 PM: ​
4:20:36 PM:   Resolved config
4:20:36 PM:   build:
4:20:36 PM:     command: hugo --gc --minify
4:20:36 PM:     commandOrigin: ui
4:20:36 PM:     publish: /opt/build/repo/public
4:20:36 PM:     publishOrigin: ui
4:20:37 PM: Caching artifacts
4:20:37 PM: Started saving build plugins
4:20:37 PM: Finished saving build plugins
4:20:37 PM: Started saving pip cache
4:20:37 PM: Finished saving pip cache
4:20:37 PM: Started saving emacs cask dependencies
4:20:37 PM: Finished saving emacs cask dependencies
4:20:37 PM: Started saving maven dependencies
4:20:37 PM: Finished saving maven dependencies
4:20:37 PM: Started saving boot dependencies
4:20:37 PM: Finished saving boot dependencies
4:20:37 PM: Started saving rust rustup cache
4:20:37 PM: Finished saving rust rustup cache
4:20:37 PM: Started saving go dependencies
4:20:37 PM: Finished saving go dependencies
4:20:40 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
4:20:40 PM: Creating deploy upload records
4:20:40 PM: Failing build: Failed to build site
4:20:40 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
4:20:40 PM: Finished processing build request in 19.968050701s

I see a handful of other threads here that suggested making sure the themes directory is available, so I committed that to my site’s Git repository, but that still didn’t help.

Can anyone advise on what I might be missing and how to fix this? Thank you!

I checked and your themes folder appears to be empty: Files · main · Pen-Yuan Hsing / Personal site · GitLab

Did you try to do what the error says?

Maybe try doing as Hugo docs suggest: Use Hugo Modules | Hugo?

1 Like

Thank you @hrishikesh, :heart:

I completely gave up using themes via Git submodules, and instead used a theme via Go (Hugo) modules as you suggested with this guide. Now my site is building and deploying correctly.

I guess for some reason the build process for Hugo sites is having trouble pulling in Git submodules?

Anyway, thank you for your suggestion.