Modules: Error: File does not exist

A while ago I had built a rudimentary “plugin” system into my theme Midnight and now that Hugo Modules are out, I’ve been trying to break optional behavior out of the main repo and into modules. I keep getting errors though and I’m not sure what is causing the problem.

Links to relevant repos will be provided at the bottom of this post. I’m using the latest GitHub release of Hugo for FreeBSD.

Hugo Static Site Generator v0.58.2-253E5FDC freebsd/amd64 BuildDate: 2019-09-13T08:04:29Z

Module Does Not Exist

The first issue I run into is that hugo mod get -u seems to download all of the modules correctly, but will then print an error on the last module:

Error: module "[NAME]" not found; either add it as a Hugo Module or store it in "[THEME_DIR]".: module does not exist

I tried shuffling the import order around in config.toml and it always errors only on the last module. I have run hugo mod init in all of the module repos and configured [module] inside of their configuration files.

File Does Not Exist

To see if I could work around the above issue, I replaced the import paths from module paths to the name of the local folder inside themes/ so it wouldn’t try to fetch them. That led to another error:

Error: add site dependencies: load resources: loading templates: walk: open "[FOLDER]" (""): file does not exist

Where [FOLDER] is the last folder in a mount configured in the module itself. So for example, the commento plugin has the following configuration:

    source = "partials"
    target = "layouts/partials/comments/commento"
    source = "css"
    target = "assets/css/comments/commento"

The error would then say ... open "commento" (""): file does not exist. In this case it’s referring to the “partials” mount target (determined by changing the name of the last folder in both targets). This error occurs with multiple modules, though, which is why I generalized the error message.

Another user mentioned having this error in another thread but there has been no response.

Could someone take a look at my repos and try and help debug these issues? The theme is a bit complex, but knowledge of the innards shouldn’t be necessary. The modules I’ve split off were copied directly, with the only changes being that a folder, e.g. layouts/partials/comments/commento, had the unnecessary empty parent folders removed, e.g. /partials, but the mounts are configured to be at the same location they were before splitting…

All links point to the correct branch (all use master except Midnight, which uses branch develop). The config.toml files of the website and Midnight are configured to use local copies of the submodules but have commented entries to download them as modules.

A couple other things I realized I should mention:

  • Branch master of Midnight is not configured as a module yet and that is what hugo mod will download by default. In my testing that got these errors, I had the website configured to use the local version.
  • One thing that could be messing things up - but hasn’t in the past - is that I locally replace the themes/ folder in the site with a symbolic link to ../themes so that I can share a themes folder among multiple sites without having to remember to pass the --themesDir flag. It makes it easier to test changes on multiple sites at once.

I quickly scanned your projects, and my first guess would be that you got the “source” wrong. The above tells Hugo to look for a directory named partials relative to the project/module. Also note that the mounts applies to the project they’re defined in – and sub modules can also provide mount configuration.

I’m not sure if I’m misunderstanding how mounts work.

So if a submodule A has the following configuration:

    source = "foo"
    target = "layouts/partials/foo"

Any project B using this as a submodule will have A/foo mounted to B/layouts/partials/foo without needing to add [[module.imports.mounts]] to B’s configuration. Is this correct?

If it is, then source = "partials" should be correct, as the Commento module has a partials/ folder at the root of the module.


I will look at your project later. I notice you’re using Gitlab. I’m not expecting that to be an issue, but it’s not sommething I’ve tested.

1 Like

It isn’t an issue with Go modules, for what that’s worth. So any issues would be Hugo-specific.

What OS are you running this from?

This is on FreeBSD, using the latest release binary hosted on GitHub. The full version string is at the beginning of the first post.

1 Like

Politely wondering if anyone has found anything helpful. This error is preventing me from doing any more work on my Hugo theme.

I am not on FreeBSD, neither do I contribute to Hugo’s code base, so I am afraid that I cannot help here, but I have noted that your theme Midnight is affected by the issue described in this topic and I will make sure to keep your theme in the Hugo Themes Showcase, when issue hugoThemes/issues/682 is addressed at the end of the month.

1 Like