Hugo Module Not Found
I plan to add a theme to my Hugo site using Go modules instead of the usual Git submodules. Following guide on https://gohugo.io/hugo-modules/use-modules/
hugo mod init github.com/ycprog/resume
Now add my desired theme in the config.toml
[module]
[[module.imports]]
path = 'github.com/spf13/hyde'
Then tidy up the module.
hugo mod tidy
Surprisingly I’ve encounter this error
go: added github.com/spf13/hyde v1.1.0
Error: module "hyde" not found; either add it as a Hugo Module or store it in "/e/workspace/resume/themes".: module does not exist
Running hugo mod vendor
yields similar results as well
Error: module "hyde" not found; either add it as a Hugo Module or store it in "/e/workspace/resume/themes".: module does not exist
I have double check and ensure that I have follow the steps exactly. They look simple and straightforward, and pretty sure I have the necessary tools installed correctly on my environment.
How do I fix it?
Doing a number of search online yields no result. After some trial and error, I finally found the solution to this issue.
In my config.toml
, I have my configs laid out this way
theme = ["hyde"]
[module]
[module.hugoVersion]
extended = true
min = "0.90.1"
[[module.imports]]
path = 'github.com/spf13/hyde'
Now here is the issue. It seems that the module.imports
have to be declared before the theme
config before you can use it as your theme. Swapping them around fixes the problem.
[module]
[module.hugoVersion]
extended = true
min = "0.90.1"
[[module.imports]]
path = 'github.com/spf13/hyde'
theme = ["hyde"]
In fact you can even omit the config theme = ["hyde"]
as the theme is auto included and the order of the theme is determined by the order of the module.imports
.
Verifying the fix
Run hugo mod tidy
again
Done in 0.28s.
Open up go.mod
, you can also see the module added successfully
module github.com/ycprog/resume
go 1.19
require (
github.com/spf13/hyde v1.1.0 // indirect
)
Such an easy solution (or mistake?) yet it is easy to miss out. Searching Google is not helpful but I am glad that I did not take too long to figure out my foolishness. I hope this will be helpful for anyone who encounter the same issue as me but is unable to spot the blunder.
You May Also Like
When a Golang nil error is not nil
Coding in Golang are usually fun and easy for developers that are new to the language. There are sometimes gotcha which will catch out even experience …
Read ArticleCrash Course on Golang Benchmarks: A Beginner's Perspective
Golang, renowned for its simplicity and efficiency, employs benchmark testing as a fundamental tool for performance evaluation. In this exploration, …
Read Article