Private hugo modules not working even though go get works fine

I am trying to use a private Hugo module on my website. I configured git to use SSH and set the GOPRIVATE environment variable as well. After this go get was successfully able to fetch my private module.

However, running hugo mod get is not able to fetch it.

go mod download: github.com/UtkarshVerma/hugo-yoru@v0.0.0-20220109123722-1082095a19ab: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /home/subaru/.cache/hugo/modules/filecache/modules/pkg/mod/cache/vcs/3ad850ae5127b0c7fc8bae86a06c9f9b6b8512243fc5c7e8f26205020d5849e7: exit status 128:
	fatal: could not read Username for 'https://github.com': terminal prompts disabled
hugo: collected modules in 1877 ms
WARN 2022/01/09 19:36:39 failed to download modules: failed to execute 'go [mod download]': failed to execute binary "go" with args [mod download]: go mod download: github.com/UtkarshVerma/hugo-yoru@v0.0.0-20220109123722-1082095a19ab: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /home/subaru/.cache/hugo/modules/filecache/modules/pkg/mod/cache/vcs/3ad850ae5127b0c7fc8bae86a06c9f9b6b8512243fc5c7e8f26205020d5849e7: exit status 128:
	fatal: could not read Username for 'https://github.com': terminal prompts disabled
 *errors.errorString
go: github.com/UtkarshVerma/hugo-yoru@v0.0.0-20220109123722-1082095a19ab: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /home/subaru/.cache/hugo/modules/filecache/modules/pkg/mod/cache/vcs/3ad850ae5127b0c7fc8bae86a06c9f9b6b8512243fc5c7e8f26205020d5849e7: exit status 128:
	fatal: could not read Username for 'https://github.com': terminal prompts disabled

Related:
https://github.com/gohugoio/hugo/issues/9333

1 Like

I think the proper way is to rename your source to something like username:pat@github.com/username/reponame where the username is your (cloner) username and pat is a “personal access token” that you can create at Sign in to GitHub · GitHub. There are also ways to put the PAT into your environmental vars, but I am not sure how or if Hugo will read that.

I was using a personal access token. There is a bug in the latest Hugo version which the above-mentioned issue mentions.

1 Like