Weird error while trying to mount a file in a module

I read in one of the modules related posts recently that an undocumented ability of Hugo modules mounts feature is, that it’s able to mount files instead of directories. So I tried to change

[[module.mounts]]
source = "data"
target = "data"

to

[[module.mounts]]
source = "data/dnb/shortcodes/config.toml"
target = "data/dnb/shortcodes/config.toml"

but I ended up with the following error:

Change of config file detected, rebuilding site.
2020-12-07 20:46:18.886 +0700
hugo: downloading modules …
hugo: collected modules in 3709 ms
ERROR 2020/12/07 20:46:22 Failed to reload config:

ERROR 2020/12/07 20:46:22 Add site dependencies: create deps: create PathSpec: build filesystems: this fs supports directories only
github.com/gohugoio/hugo/hugolib.newHugoSites
        /root/project/hugo/hugolib/hugo_sites.go:380
github.com/gohugoio/hugo/hugolib.NewHugoSites
        /root/project/hugo/hugolib/hugo_sites.go:519
github.com/gohugoio/hugo/commands.(*commandeer).loadConfig.func3
        /root/project/hugo/commands/commandeer.go:402
sync.(*Once).doSlow
        /usr/local/go/src/sync/once.go:66
sync.(*Once).Do
        /usr/local/go/src/sync/once.go:57
github.com/gohugoio/hugo/commands.(*commandeer).loadConfig
        /root/project/hugo/commands/commandeer.go:361
github.com/gohugoio/hugo/commands.(*commandeer).fullRebuild.func1
        /root/project/hugo/commands/hugo.go:812
runtime.goexit
        /usr/local/go/src/runtime/asm_amd64.s:1374
Rebuilt in 4112 ms

Change of config file detected, rebuilding site.
2020-12-07 20:46:46.854 +0700
WARN 2020/12/07 20:4

Am I doing it wrong or is this “feature” more or less based on the available hardware/file system?

bep mentioned a solution in another issue: Hugo Module Mounts: use root file as source

I had the same issue and loaded my file to the assets folder instead as suggested:

[[module.imports.mounts]]
    source=".github/workflows/deploy_prod.yaml"
    target="assets/configs/deploy_prod.yaml"

Then in the shortcode, I load the “asset” through the resources method and apply the transform as suggested by bep

{{ $deployProd := resources.Get "configs/deploy_prod.yaml" | transform.Unmarshal }}

Worked like a charm.

1 Like