How to use module mount for themes as symlinks no longer work in Hugo 0.123+

Hello,

Before Hugo 0.123, I could use symlinks in Hugo child projects, like linking the entire theme/ directory. How can I do it using module mount feature?

I have tried:

module:
  mounts:
    - source: /Users/user/Git/parent-project.com/themes
      target: themes

… but it didn’t work and failed with error:

Error: command error: failed to load modules: failed to apply mounts for project: invalid module config for "project": mount target must be one of: [archetypes assets content data i18n layouts static]

I’m holding out hope that I’ve overlooked something, and there’s still a way to share themes with child projects without having to duplicate them?

Initialize your site as a module:

hugo mod init foo

In the above, foo is typically something like github.com/jmooring/my-site.

Then in your site config:

[[module.imports]]
path = "/Users/user/Git/parent-project.com/themes/my-theme"

When you do this, remove themes = ['foo'] from your site config. The module.imports is all you need.

Thanks, Joe!

I do have a follow-up question, though. How does this all improve over a simple symlink? If it’s more secure, can you explain how exactly?

Reasoning behind removal of symlink support, which I fully support:
https://github.com/gohugoio/hugo/issues/11556

Those are valid points! However, it seems those reasons force users into dealing with higher complexity and/or making significant changes to existing projects. This isn’t always desirable. Even though the developers’ intentions are noble, it will create a lot of mess and extra work for projects that currently rely on using symlinks. I believe it wouldn’t cost the Hugo developers anything to just add a --allow-symlinks flag?

That is not going to happen. Sorry.

Thank you for the information provided, Joe!

Though, I believe many people would appreciate it if you reconsidered. While modules are indeed better, reconfiguring many large projects could be very time-consuming.

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