Go mod init and go mod tidy

This is not a specific question about Hugo. I have updated go from version 1.21 to 1.22.1. Then I ran go mod init and go mod tidy. I got the following error message: go: warning: “all” matched no packages.

With go version 1.21, go mod init and go mod tidy work without errors. How do I load the modules in Hugo?

go.mod


module test

go 1.21.0

require github.com/gohugoio/hugo-mod-bootstrap-scss/v5 v5.20300.20003 // indirect

go.sum

github.com/gohugoio/hugo-mod-bootstrap-scss/v5 v5.20300.20003 h1:pt/JGVD5YYRsVVijOHPZI6YKTUvbR4e0hgV9B0S6rbI=
github.com/gohugoio/hugo-mod-bootstrap-scss/v5 v5.20300.20003/go.mod h1:mvM05r93HiefwoaxQTaYiJxtJAhTebwQtU1Xh/J+Okk=
github.com/gohugoio/hugo-mod-jslibs-dist/popperjs/v2 v2.21100.20000/go.mod h1:mFberT6ZtcchrsDtfvJM7aAH2bDKLdOnruUHl0hlapI=
github.com/twbs/bootstrap v5.3.0+incompatible/go.mod h1:fZTSrkpSf0/HkL0IIJzvVspTt1r9zuf7XlZau8kpcY0=

Try running GoHugo’s “go mod replacements” (? not sure):

hugo mod tidy

Not sure about init because that is only needed the first time you create a module.

When any hugo mod command throws errors at me I tend to just delete go.sum, then remove the require parts of go.mod and run hugo mod get -u ./... which most times solves the issue.

If that does not solve the issue you need to post your module setup ([module.imports] sections in your config) for us to know what is going on.

Here what I have done:

$ go mod init developer
$ hugo mod tidy
$ hugo server

The first mistake was to import the icons in the styles.css

/* import the necessary Bootstrap files */
@import "bootstrap/functions";
@import "bootstrap/variables";
@import "bootstrap-icons/bootstrap-icons.css";
hugo.toml

[module]
	[[module.imports]]
		path = "github.com/gohugoio/hugo-mod-bootstrap-scss/v5"
  [[module.imports]]
    path = "github.com/twbs/icons"
  [[module.imports.mounts]]
    source = "icons"
    target = "assets/icons"

The second mistake was, that I have changed the module name from example.com to developer. I used the command

go mod init developer
hugo mod tidy

Than I get the error message:

Error: error building site: process: readAndProcessContent: “/home/code-server/Workspace/developer/content/en/brand-guidelines.md:8:1”: failed to extract shortcode: template for shortcode “row” not found

Do I change back from developer to example.com in the go.mod Hugo works fine. Why I can’t change module name?

The icons are located in /public/assets/icons. Now the icons only need to be included in the head.html.

hugo server
Watching for changes in /home/code-server/Workspace/developer/{archetypes,content,data,i18n,themes}
Watching for config changes in /home/code-server/Workspace/developer/hugo.toml, /home/code-server/Workspace/developer/go.mod
Start building sites …
hugo v0.124.0-629f84e8edfb0b1b743c3942cd039da1d99812b0+extended linux/amd64 BuildDate=2024-03-16T15:44:32Z VendorInfo=gohugoio

ERROR TOCSS-DART: failed to transform “/scss/styles.a6e1309d9da3dd5f4341014b25fb2b9ae7429db81a1c2a0e6839972a941b7a3f.scss” (text/x-scss): “/home/code-server/Workspace/developer/themes/developer/assets/scss/styles.scss:4:8”: Can’t find stylesheet to import.
Built in 108 ms

Ho do I right? This example doesn’t work.

<!-- Dart Sass -->
{{ $opts := dict "transpiler" "dartsass" }}
{{ $scss := resources.Get "scss/styles.scss" | fingerprint }}
{{ $fonts := resources.Get "css/font-icons.css"}}
{{ $styles := $scss | resources.ToCSS $opts }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" />