Hugo latest version can't support server command under exampleSite subfolder?

Recently, I were upgrade Hugo to latest version which use build Hugo docs repository in local. But then I found that it can’t working for myself Hugo’s theme develop. When I use the below command then got errors.

$ hugo version
hugo v0.87.0-B0C541E4 windows/amd64 BuildDate=2021-08-03T10:57:28Z VendorInfo=go
hugoio
$ cd my-hugo-theme/exampleSite
$ hugo sever -t ../..
Error: module "hugo-theme-next" not found; either add it as a Hugo Module or sto
re it in "D:\\GitRepos\\hugo-theme-next\\exampleSite\\themes".: module does not
exist

Is there anyone got the same issues? Please tell me how to fix it. Thanks.

Seems there about the Hugo modules usage, but when I want init the module still got failed:

So I can’t understand what’s happen!

I think you are experiencing this bug:
https://github.com/gohugoio/hugo/issues/8940

Let’s say your site configuration look like this:

[[module.imports]]
path = "github.com/example/my-module"

If you have not initialized your project as a Hugo module, you will see this error when you attempt to build your site:

Error: module “github.com/example/my-module” not found; either add it as a Hugo Module or store it in “[…]/themes”.: module does not exist

This error is not helpful. Instead, it should instruct you to initialize your project as a Hugo module.

So let’s do that:

hugo mod init foo/my-project

But this generates the same error:

Error: module “github.com/example/my-module” not found; either add it as a Hugo Module or store it in “[…]/themes”.: module does not exist

Until the bug is fixed…

  1. Comment the module import in your site configuration.

    # [[module.imports]]
    # path = "github.com/jmooring/hugo-content"
    
  2. Initialize your project as a Hugo module.

    hugo mod init foo/my-project
    
  3. Uncomment the module import in your site configuration.

    [[module.imports]]
    path = "github.com/jmooring/hugo-content"
    

@jmooring Thanks for your reply. But that’s not the answer I was looking for. I’m mean when developing the Hugo theme in local then need use hugo server -t ../.. command to preview how it effect.

Today I upgrade the Hugo latest version too, seems it can working normal. But I still interesting how to use go module way to install a theme from github website. Could you had some experience about this way?

Thanks.

@elkan1788

If you are using a theme with a demo site in exampleSite and want to use the theme to deploy exampleSite, I recommend using the HUGO_MODULE_REPLACEMENTS environment variable.

I use this with

to deploy exampleSite on Netlify with the current version of the module on a particular branch.

In the Netlify UI I have:

Variable Value
HUGO_MODULE_REPLACEMENTS github.com/danielfdickinson/cupper-hugo-dfd-x -> ../../../repo
HUGO_BASEURL https://cupper-hugo-dfd-x.wildtechgarden.ca
HUGO_VERSION 0.88.1

To do this locally on Windows 10 using the default PowerShell CLI:

$Env:HUGO_MODULE_REPLACEMENTS = "github.com/danielfdickinson/cupper-hugo-dfd-x -> ..\..\..\cuper-hugo-dfd-x"
hugo server -b http://localhost:1313/

with hugo version 0.88.1

and on Linux:

HUGO_MODULE_REPLACEMENTS="github.com/danielfdickinson/cupper-hugo-dfd-x -> ../../../cupper-hugo-dfd-x" hugo server -b http://localhost:1313/