Modular Hugo on Netlify

Did anyone get Hugo with (private and public) modules to work on Netlify? Neither did I :wink:

First the error “fatal: could not read Username for ‘’: terminal prompts disabled” came up. I solved that by adding a line to my deploy script:

git config --global --add url."".insteadOf ""

This forces git to use ssh instead of https.

Then the following error pops up:

8:23:49 PM: 	Host key verification failed.
8:23:49 PM: 	fatal: Could not read from remote repository.
8:23:49 PM: 	Please make sure you have the correct access rights
8:23:49 PM: 	and the repository exists.

on ALL modules, even the public ones. Creating a deploy key on Netlify and adding it on Github does not solve this, but seems to be what everyone is advising.

I finally thought I got “it” working by adding all modules as vendor directory:

hugo mod vendor

But that added only the public modules to the _vendor directory. One private module is missing.

Long story short, for now I am committing the public directory to publish on Netlify while using modules with Hugo. How are your experiences?

I managed to do it with a hack. I documented it in this note, but short version is: 1) pass each module’s deploy key to the build via environment variables, 2) run build with a custom script that clones each module via git-ssh, and 3) point hugo to the locally cloned modules using the replacements mechanism.

That is an extremely clever idea. I will test this out.