git clone --single-branch -b hugo-workspace https://github.com/deining/hugo-test
cd hugo-test/exampleSite/
hugo mod vendor
Build of the site fails:
hugo
Total in 3 ms
Error: failed to load modules: invalid modules list: "/home/andreas/hugo-test/exampleSite/hugo-test/exampleSite/_vendor/modules.txt"
Reason:
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
1,2c1
< # github.com/deining/hugo-test v0.0.0-20240224154229-8a2fa5c92c75
< ## explicit; go 1.21.7
---
> # github.com/deining/hugo-test 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.
I’ve been using a workspace file for local testing and setting a local env variable in the terminal (export HUGO_MODULE_WORKSPACE=hugo.work). 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.