"Module not Found..."

I’m trying to figure this out and would appreciate any feed back. Basically, I’m moving stuff to repos, and also trying to be more HUGO MODular, but have run into some strange behavior.

I have a repo which will be the main content repo (AKA “the website”). This repo pulls in a theme via mods from a local folder (I know that routing the theme locally rather than via github will be faster/easier for rapid development).

So my main site/config.yml file looks like:

...

themesDir : ../ #theme folder lives above

module :
  imports :
    - path : hugo-theme

...

So far, so good (this repo also has a go.mod and go.sum file.

“Hugo-Theme” is a repo with a go.mod and go.sum file as well as a config.yml file where I want to pull some dependencies.

In the past I have used Hugo Mods to pull some JS libraries from Github – I use this fro my dependency management. It seems to work well (at least for my use cases).

So, within hugo-theme/config.yml it looks like this:

module :
  imports :
    - disable : false
      path : github.com/processing/p5.js-website
      mounts :
        - source : src/assets/js/
          target : assets/js/vendor

And, within hugo-theme/layouts/index.html I have:

{{- $p5 := resources.Get "js/vendor/p5.min.js" -}}
{{- with $p5 -}}<script src="{{ .Permalink }}"></script>{{- end -}}

When I run the site I get the following readout:

$ hugo serve -D --disableFastRender
hugo: downloading modules …
go: finding github.com/processing/p5.js-website latest
go: downloading github.com/processing/p5.js-website v0.0.0-20191128063215-f4e4dec930b8
go: extracting github.com/processing/p5.js-website v0.0.0-20191128063215-f4e4dec930b8
hugo: collected modules in 53101 ms
Error: module "github.com/processing/p5.js-website" not found; either add it as a Hugo Module or store
 it in "/.../Documents/GitHub".: module does not exist

Hmmmmmmm…

and the thing is: it all works when the module is listed and imported when it is the in the main site/config.yml.

I’m not sure whats happening… thoughts?

Check whether there is some difference in the generated hash between earlier and recent versions of Hugo.

I encountered the “Module not found” error in a theme submission at the Hugo Themes repo, more here: https://github.com/gohugoio/hugoThemes/issues/713#issuecomment-557814781

1 Like

so I just read this: Kodify · Programming articles and code tutorials

Which says:

The config.toml file that’s included with most themes (usually in the theme’s /exampleSite/ folder) contains the theme’s example settings . This file is not a configuration file and does not affect Hugo’s behaviour (and we can even safely delete it). We use a theme’s config.toml file only to see what theme settings we should include in our configuration file and the values those options accept.

Is this true? I could understand it not being used if within the /exampleSite/ folder, but if it is a top-level config file, I would assume that it would be folded into the site’s config ?

(I’ll also check on those hashes…)

The quote you linked to is from 2017.

Since Allow some config from themes by bep · Pull Request #4514 · gohugoio/hugo · GitHub was merged in 2018, config files directly under the root of /theme/ gained the following functionality:

This allows a config.toml in the theme to set

  1. params (but cannot override params in project. Will also get its own “namespace”, i.e. {{ .Site.Params.mytheme.my_param }} will be the same as {{ .Site.Params.my_param }} providing that the main project does not define a param with that key.
  2. menu – but cannot redefine/add menus in the project. Must create its own menus with its own identifiers.
  3. languages – only params and menu . Same rules as above.
  4. new outputFormats
  5. new mediaTypes

The config under /exampleSite/ does indeed refer to the exampleSite project and as such it is not inherited by a project that uses its parent theme.

But the config under the root of a theme is inherited by a project that uses this theme.

The config under the root of a Hugo project can override the config of a theme, but not the other way around.


cc: @bep

Cool, just making sure. :+1:

Hashes look good ( i think? )

And now I’m getting the following error…

go get .: path /Users/.../Documents/GitHub/hugo-theme is not a package in module rooted at /Users/.../Documents/GitHub/hugo-theme

doe this help clarify the issue?

Actually I am probably not the best in debugging Go(aka Hugo) modules.

but let’s give this a try. What is the Go version installed locally?

Try issuing the command go get -v with the -v flag that is.

Did the module mount?

If not you may need to provide access to your project for us to have a look locally.

let me make a set of “clean repos”, see if i can’t reproduce, and then i’ll share with all.

I get the same error when using a theme via modules. I have no problem getting the theme working, but when I try to run hugo mod get -u, I get that error message referring to my project path.

tom@ladybird exampleSite$ hugo mod get -u
go get .: path /mnt/c/Users/Tom/Sync/home/exampleSite is not a package in module rooted at /mnt/c/Users/Tom/Sync/home/exampleSite

I’m reading all I can about Go modules, but I’d definitely appreciate being pointed in the right direction so I can figure this out faster.

I followed the steps here: Hugo modules for "dummies" and then I get the error when trying to update modules.

go version go1.13.4 linux/amd64

The quick and dirty way to update modules is to delete your go.mod and go.sum files and run the command
hugo mod init described on this link
The problem with this solution is that it would pull in all your latest updates from all connected modules.

Thanks, that’s what I’ve done, and I also realize you can update modules individually and that has worked fine for me too. But I’d really like to know what is going on with this error. I guess I just have to learn more about Go Modules.

Maybe the error is because there are no Go packages in my directory that makes up my Hugo site?

Ok, I figured out why the problem occurs. I had the same problem when adding another module. The issue was that one can’t use the new go.mod / go.sum from the theme in exampleSite until the theme can be found by go get.

There are two possible solutions:

  1. Push the theme then update exampleSite
  2. Use the development option to replace a module in go.sum / go.mod with a local path for development (but don’t forget to remove that config before committing and pushing). https://gohugo.io/hugo-modules/use-modules/#make-and-test-changes-in-a-module has the basic information.

In a working scenario my theme go.mod looks like:

 module github.com/cshoredaniel/new-oldnew-mashup

go 1.13

require (
        github.com/cshoredaniel/julmot-mark.js v0.0.0-20181210172629-31a7315c6024 // indirect
        github.com/cshoredaniel/necolas-normalize.css v2.1.3+incompatible // indirect
        github.com/cshoredaniel/plainfuse v0.0.0-20200304153200-190c16c2024d // indirect
)

replace github.com/cshoredaniel/new-oldnew-mashup => /home/daniel/devpath/new-oldnew-mashup

and my exampleSite go.mod looks like:

module github.com/cshoredaniel/new-oldnew-mashup-example

go 1.13

require (
        github.com/cshoredaniel/julmot-mark.js v0.0.0-20181210172629-31a7315c6024 // indirect
        github.com/cshoredaniel/necolas-normalize.css v2.1.3+incompatible // indirect
        github.com/cshoredaniel/plainfuse v0.0.0-20200304153200-190c16c2024d // indirect
)

replace github.com/cshoredaniel/new-oldnew-mashup => /home/daniel/devpath/new-oldnew-mashup

replace github.com/cshoredaniel/new-oldnew-mashup-example => /home/daniel/devpath/new-oldnew-mashup/exampleSite

Note that when actually committing module github.com/cshoredaniel/new-oldnew-mashup-example is module github.com/cshoredaniel/new-oldnew-mashup is the exampleSite go.mod.

Hope that helps someone who runs across the same issue.

1 Like

Thanks for the info. I will experiment with it sometime soon. For now I just went back to using Git submodules to install themes.