Invalid modules list when using hugo workspace


git clone --single-branch -b hugo-workspace
cd hugo-test/exampleSite/
hugo mod vendor

Build of the site fails:

Total in 3 ms
Error: failed to load modules: invalid modules list: "/home/andreas/hugo-test/exampleSite/hugo-test/exampleSite/_vendor/modules.txt"


The file modules.txt generated from hugo is different from that one generated by go:

go mod vendor
diff vendor/modules.txt _vendor/modules.txt 
< # v0.0.0-20240224154229-8a2fa5c92c75
< ## explicit; go 1.21.7
> # or/modules.txt _vendor/modules.txt

The only module listed inside the file m̀odules.txt generated from hugo mod vendor does not held version information, which causes hugo to exit prematurely.

Please log an issue and cross-reference to this topic.

It should be different. Hugo has its own vendoring code. So go mod vendor will always differ from hugo mod vendor.

I’m not saying that the above isn’t a issue/problem, just that your conclusion about the cause is wrong.

Also, if you somehow did go mod vendor and then renamed vendor to _vendor, this would explain the above.

I’ve had this problem too.

I’ve been using a workspace file for local testing and setting a local env variable in the terminal (export Running hugo mod vendor produces the invalid modules list.

But, using unset removes the env var (unset HUGO_MODULE_WORKSPACE), delete the entire _vendor dir, and then hugo mod vendor works correctly.

I’m guessing deleting this line in the hugo-test repo would fix things.

Here’s the GH issue if anyone else runs across this → Invalid modules list when using hugo workspace · Issue #12154 · gohugoio/hugo · GitHub