gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
75.76k stars 7.53k forks source link

CSS files not found when vendoring modules in v0.123.x #12137

Closed markdumay closed 8 months ago

markdumay commented 8 months ago

What version of Hugo are you using (hugo version)?

hugo v0.123.3-a75a659f6fc0cb3a52b2b2ba666a81f79a459376+extended darwin/arm64 BuildDate=2024-02-23T17:09:20Z VendorInfo=brew

Does this issue reproduce with the latest release?

Yes

Context

When upgrading Hugo from v0.122.0 to v0.123.3 I get a CSS transpiler error. Below the full error logs (specific to the Hinode theme):

ERROR render of "taxonomy" failed: execute of template failed: template: partials/head/head.html:8:7: executing "head" at <partialCached "head/stylesheet-core.html" .>: error calling partialCached: "[...]/hinode/layouts/partials/head/stylesheet-core.html:3:3": execute of template failed: template: partials/head/stylesheet-core.html:3:3: executing "partials/head/stylesheet-core.html" at <partial "head/stylesheet.html">: error calling partial: "[...]/hinode/layouts/partials/head/stylesheet.html:60:12": execute of template failed: template: partials/head/stylesheet.html:60:12: executing "partials/head/stylesheet.html" at <partial "head/icons.html" (dict "css" $css)>: error calling partial: "[...]/hinode/layouts/partials/head/icons.html:22:54": execute of template failed: template: partials/head/icons.html:22:54: executing "partials/head/icons.html" at <$css.Content>: error calling Content: TOCSS: failed to transform "css/main.css" (text/x-scss): "[...]/hinode/_vendor/github.com/gethinode/mod-bootstrap/assets/scss/bootstrap.scss:7:1": File to import not found or unreadable: modules/bootstrap/mixins/banner.
ERROR render of "404" failed: execute of template failed: template: partials/head/head.html:8:7: executing "head" at <partialCached "head/stylesheet-core.html" .>: error calling partialCached: "[...]/hinode/layouts/partials/head/stylesheet-core.html:3:3": execute of template failed: template: partials/head/stylesheet-core.html:3:3: executing "partials/head/stylesheet-core.html" at <partial "head/stylesheet.html">: error calling partial: "[...]/hinode/layouts/partials/head/stylesheet.html:60:12": execute of template failed: template: partials/head/stylesheet.html:60:12: executing "partials/head/stylesheet.html" at <partial "head/icons.html" (dict "css" $css)>: error calling partial: "[...]/hinode/layouts/partials/head/icons.html:22:54": execute of template failed: template: partials/head/icons.html:22:54: executing "partials/head/icons.html" at <$css.Content>: error calling Content: TOCSS: failed to transform "css/main.css" (text/x-scss): "[...]/hinode/_vendor/github.com/gethinode/mod-bootstrap/assets/scss/bootstrap.scss:7:1": File to import not found or unreadable: modules/bootstrap/mixins/banner.
ERROR render: failed to render pages: render of "home" failed: execute of template failed: template: partials/head/head.html:8:7: executing "head" at <partialCached "head/stylesheet-core.html" .>: error calling partialCached: "[...]/hinode/layouts/partials/head/stylesheet-core.html:3:3": execute of template failed: template: partials/head/stylesheet-core.html:3:3: executing "partials/head/stylesheet-core.html" at <partial "head/stylesheet.html">: error calling partial: "[...]/hinode/layouts/partials/head/stylesheet.html:60:12": execute of template failed: template: partials/head/stylesheet.html:60:12: executing "partials/head/stylesheet.html" at <partial "head/icons.html" (dict "css" $css)>: error calling partial: "[...]/hinode/layouts/partials/head/icons.html:22:54": execute of template failed: template: partials/head/icons.html:22:54: executing "partials/head/icons.html" at <$css.Content>: error calling Content: TOCSS: failed to transform "css/main.css" (text/x-scss): "[...]/hinode/_vendor/github.com/gethinode/mod-bootstrap/assets/scss/bootstrap.scss:7:1": File to import not found or unreadable: modules/bootstrap/mixins/banner.
Built in 140 ms
Error: error building site: TOCSS: failed to transform "css/main.css" (text/x-scss): "[...]/hinode/_vendor/github.com/gethinode/mod-bootstrap/assets/scss/bootstrap.scss:7:1": File to import not found or unreadable: modules/bootstrap/mixins/banner.

The error only occurs when running hugo mod vendor.

To reproduce

git clone https://github.com/gethinode/hinode.git
cd hinode
hugo mod vendor
hugo server

Removing the _vendor directory solves the TOCSS transpiler error (it doesn't seem to matter if using libsass or dartsass).

rm -rf _vendor
hugo server

Rationale

The Hinode theme vendors its modules to add specific CSS files to a safe list, preventing certain style definitions to be purged from the final CSS file. See config/postcss.config.js for more details. Purge is enabled by setting purge = true in the[style] section of config/_default/params.toml.

bep commented 8 months ago

I just tested this OK:

hugo new site my-hinode-site && cd my-hinode-site
hugo mod init example.com/my-hinode-site
echo "[[module.imports]]" >> hugo.toml
echo "path = 'github.com/gethinode/hinode'" >> hugo.toml
hugo mod vendor
hugo server

You are right that it fails when running the vendored version directly from the theme, but comparing the vendored directories from v0.122 and v0.123 shows that they are the same, which means that it's not the vendoring that's failing.

Hmm.

bep commented 8 months ago

OK, I think I see what's happening now.

markdumay commented 8 months ago

That’s encouraging!

As a side note, the single reason to vendor the modules is to provide a consistent path for the safe listed files for the purge-css utility. As far as I’m aware, these (external) utilities do not have access to the Hugo mounts. But perhaps there’s a more elegant approach?

github-actions[bot] commented 7 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.