Package.json like version manager for Hugo?

Hello friends!

Let’s say I have an old website that was built with an older version of Hugo.

If I install Hugo on a different PC or laptop, the official installers always installs the latest version.

Why isn’t there something like a package.json file, where a specific version of the framework is defined? With tools like npm, you can run npm install and automatically install the exact version required to run the website without surprise errors.

My main concern is if my website was built with an older version of Hugo, what happens if some methods or functions are deprecated or removed in newer versions? I might run into errors?

Technically, it would make much more sense if I could install and run a specific version of Hugo required for each site based on version control system.

Don’t you think it’s a necessary feature?

@user645235 see GitHub - jmooring/hvm: Hugo Version Manager.

1 Like

The Hugo Version Manager that was linked is great, but there are a couple of other approaches worth knowing about too:

  1. Netlify/Vercel config: If you deploy via Netlify, you can pin the Hugo version in your netlify.toml:
[build.environment]
  HUGO_VERSION = "0.139.0"

This means your CI/CD always uses the right version regardless of what is installed locally.

  1. Docker: Running Hugo in a Docker container with a pinned version tag is another solid approach for team environments. klakegg/hugo on Docker Hub has versioned tags.

  2. GitHub Actions: If you use GitHub Pages, you can pin the version in your workflow file.

But yeah, a built-in package.json equivalent would be nice. The closest Hugo has is the module system, but that manages theme dependencies rather than the Hugo binary itself. Version pinning at the project level is something a few static site generators still have not solved neatly.

Always recommended to use the same Hugo version locally and in production.

Would not recommend that for newer versions. It seems abandoned klakegg/hugo - Docker Image.

1 Like

If you’re looking for a Docker image, you might consider… the official one:
https://github.com/gohugoio/hugo/pkgs/container/hugo

Here’s an example of using the official image when building a project for GitHub Pages:
https://github.com/jmooring/hosting-github-pages-official-docker-image/blob/main/.github/workflows/hugo.yaml

In the next release, if you have this in your project configuration:

[module.hugoVersion]
min = '0.148.0'
max = '0.148.0'

And use the --panicOnWarning flag:

hugo build --gc --minify --panicOnWarning

The build will fail.

I would only use the --panicOnWarning flag for the production build, whether local or CI/CD.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.