Setting HUGO_MODULE_REPLACEMENTS uses go.mod version without error

The module is a theme. It has an exampleSite with a go.mod:


go 1.20

require v0.58.0 // indirect

When I try to build/run exampleSite using the local copy of the theme, it uses the published version of the theme.

For example, http://localhost:1313 shows a home page with the title “Paige”. If you modify the local theme copy to put a “foo” word below the title:

--- a/layouts/partials/paige/metadata.html
+++ b/layouts/partials/paige/metadata.html
@@ -19,6 +19,7 @@
 <div class="w-100" id="paige-metadata">
     {{ with $title }}
         <h1 class="fw-bold text-center" id="paige-title">{{ if $link }}<a href="{{ $link }}">{{ . }}</a>{{ else }}{{ . }}{{ end }}</h1>
+        <p>foo</p>
     {{ end }}
     {{ with $description }}

and then set HUGO_MODULE_REPLACEMENTS and HUGO_THEMESDIR, nothing changes at http://localhost:1313:

❯ env HUGO_MODULE_REPLACEMENTS='replace -> paige' HUGO_THEMESDIR=../.. hugo server

For what it’s worth, hugo mod graph doesn’t show any changes, but I’m not clear on whether that’s expected:

❯ env HUGO_MODULE_REPLACEMENTS='replace -> paige' HUGO_THEMESDIR=../.. hugo mod graph

I also tried the absolute path approach:

❯ env HUGO_MODULE_REPLACEMENTS='replace -> /Users/Will/Developer/paige' hugo server

There’s no error at all. Mapping to a non-existent directory also runs without error:

❯ HUGO_MODULE_REPLACEMENTS='replace -> /foo' hugo server

I’m not sure what I’m missing.

You need to remove the “replace”. Try:

env HUGO_MODULE_REPLACEMENTS='replace -> paige' HUGO_THEMESDIR=../.. hugo server

On a related note, the above setting was added before Go got workspace support.

See hugoDocs/ at master · gohugoio/hugoDocs · GitHub

As an example, when I do theme changes on the Hugo theme, I do this from the hugoDocs repo: hugo server --ignoreVendorPaths "**"
1 Like

Apparently I am blind. Thanks for the correction, and the workspace tip!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.