Migrating to Modules in Hugo
Go introduced modules several years ago as part of a dependency management system. My Hugo site is still using git submodules to manage its theme. I attempted to migrate to Go’s submodules but eventually ran into a snag when trying to deploy the site.
To start, remove the submodule
git submodule deinit --alland then remove the themes folder
git rm -r themesTo finish the cleanup, remove the theme key from config.toml.
Next, setup the project to use modules
go mod init github.com/danielcorin/blogand added the theme as a module to the config.toml
[module][[module.imports]] path = 'github.com/lukeorth/poison'To update the go.mod file, run
hugo mod get -uwhich should add the module to the go.mod file
module github.com/danielcorin/blog
go 1.19
require github.com/lukeorth/poison v0.0.0-20230630204947-22c6c4aba785 // indirectRunning hugo serve and hugo --gc should both still work.
I pushed this changed but it failed to build on Vercel, where I have my site deployed.
It looks like go isn’t available during build time
Running "vercel build"Vercel CLI 31.0.1Installing Hugo version 0.110.0Error: failed to download modules: binary with name "go" not foundTotal in 0 msError: Command "hugo --gc --minify --ignoreCache --verbose" exited with 255BUILD_UTILS_SPAWN_255: Command "hugo --gc --minify --ignoreCache --verbose" exited with 255I may return to this though I do have some concerns about whether fixing the issue will increase build time, which is something I’d like to avoid.
Recommended
Fresh Hugo Setup
I just did a fresh clone of my site for the first time in (probably) years. I've been using nix on my new system, so I was writing a flake to setup a...