I’m seeing a strange behavior with Hugo Modules and Dart Sass and would like to understand whether this is expected behavior, a Hugo limitation, or a bug.
This issue was discovered while working on the following my theme’s PR: watch HikaeMe’s feat/side-nav-for-small-display branch. Since new users like me can only include up to two URLs in a post, I’m writing them in plain text.
Environment
- Hugo Modules
- Dart Sass
- Bootstrap SCSS
- Theme consumed as a Hugo Module
Problem
I have a SCSS entrypoint (styles.scss) that imports Bootstrap through an intermediate SCSS file.
Failing case
styles.scss
@use "vendor/bootstrap-min";
vendor/bootstrap-min.scss
@use "bootstrap/scss/bootstrap";
When the theme is consumed as a Hugo Module from GitHub, Hugo fails with:
TOCSS-DART: failed to transform ...
Can't find stylesheet to import.
The error indicates that Dart Sass cannot resolve:
@use "bootstrap/scss/bootstrap";
from within vendor/bootstrap-min.scss.
Working case
If I remove the intermediate file and import Bootstrap directly:
styles.scss
@use "bootstrap/scss/bootstrap";
Additional observations
- The failing case works when the theme is loaded using:
theme: HikaeMein a yaml file - The failure only occurs when the theme is consumed as a Git-based Hugo Module.
bootstrap-min.scsscontains nothing except:
@use "bootstrap/scss/bootstrap";
so the only difference is whether Bootstrap is imported directly from the entrypoint or through another SCSS file.
Minimal reproduction
You can try two examples with devcontainer.
Failing example:
Working example:
Question
Is this expected behavior of Dart Sass module resolution when used through Hugo Modules?
More specifically:
- Should
@use "bootstrap/scss/bootstrap"resolve differently when it is referenced from an intermediate SCSS file versus directly from the entrypoint? - Does Hugo Module mounting affect Sass load paths in a way that would explain this behavior?
- Is there a recommended pattern for wrapping third-party SCSS imports inside theme modules?
I think this is an issue you’ll almost certainly encounter in Bootstrap v6 which is not published yet, where @import has been deprecated and @use is now the primary method.
Any insight would be appreciated. Thanks!