Understanding Dart Sass @use, error

Not sure why the following is throwing an error:

{{ with resources.Get "scss/bradbice.scss" }}
{{ $opts := dict "transpiler" "dartsass" "targetPath" "css/bradbice.css" }}
{{ with . | toCSS $opts }}
<link rel="stylesheet" href="{{ .RelPermalink }}">
{{ end }}
{{ end }}

And I’m getting

ERROR TOCSS-DART: failed to transform "/scss/bradbice.scss" (text/x-scss): "<stream>:1:1": Can't find stylesheet to import.
Total in 858 ms
Error: error building site: TOCSS-DART: failed to transform "/scss/bradbice.scss" (text/x-scss): "<stream>:1:1": Can't find stylesheet to import.

Folder structure is

/assets/scss/bradbice.scss

And that file has a bunch of @use statements (relevant because this problem didn’t occur until I started switching to using @use)

@use "reset";
@use "tokens";
@use "mixins";
@use "fonts";

My hugo env returns this:

hugo v0.139.3+extended+withdeploy darwin/arm64 BuildDate=2024-11-29T15:36:56Z VendorInfo=brew
GOOS="darwin"
GOARCH="arm64"
GOVERSION="go1.23.3"
github.com/sass/libsass="3.6.6"
github.com/webmproject/libwebp="v1.3.2"
github.com/sass/dart-sass/protocol="3.1.0"
github.com/sass/dart-sass/compiler="1.81.0"
github.com/sass/dart-sass/implementation="1.81.0"

Not sure if this has to do with Hugo modules which I had previously played with but am not using (I deleted my go.mod file).

The @use rule loads mixins, functions, and variables from other Sass stylesheets.

This error message is pretty clear: the stylesheets given as argument to @use are missing. Create (and fill) these files, any the error will go away:

$ touch assets/scss/_reset.scss
$ touch assets/scss/_tokens.scss
$ touch assets/scss/_mixins.scss
$ touch assets/scss/_fonts.scss

Does this solve your issue?

1 Like

Path should be relative to the project directory, not absolute.

touch assets/scss/_reset.scss
touch assets/scss/_tokens.scss
touch assets/scss/_mixins.scss
touch assets/scss/_fonts.scss

Those files all currently exist in assets/scss, that’s why I’m confused why there is an error.

Your code with the files in the locations you describe works fine for me. Maybe do tree assets and paste the result here.

assets
β”œβ”€β”€ code-examples
β”‚   β”œβ”€β”€ auto-size
β”‚   β”‚   β”œβ”€β”€ auto-size.html
β”‚   β”‚   └── auto-size.scss
β”‚   └── test
β”‚       β”œβ”€β”€ test.html
β”‚       └── test.scss
β”œβ”€β”€ css
β”‚   └── syntax.css
β”œβ”€β”€ data
β”‚   β”œβ”€β”€ games.json
β”‚   β”œβ”€β”€ movies.json
β”‚   └── tv.json
└── scss
    β”œβ”€β”€ _base.scss
    β”œβ”€β”€ _blog-ratings.scss
    β”œβ”€β”€ _blog.scss
    β”œβ”€β”€ _chroma.scss
    β”œβ”€β”€ _content.scss
    β”œβ”€β”€ _dialog-polyfill.scss
    β”œβ”€β”€ _fonts.scss
    β”œβ”€β”€ _home-blog.scss
    β”œβ”€β”€ _home-work.scss
    β”œβ”€β”€ _home.scss
    β”œβ”€β”€ _layout.scss
    β”œβ”€β”€ _library.scss
    β”œβ”€β”€ _mixins.scss
    β”œβ”€β”€ _print.scss
    β”œβ”€β”€ _ratings-list.scss
    β”œβ”€β”€ _ratings-single.scss
    β”œβ”€β”€ _ratings-top.scss
    β”œβ”€β”€ _reset.scss
    β”œβ”€β”€ _shortcodes.scss
    β”œβ”€β”€ _text-list.scss
    β”œβ”€β”€ _tokens.scss
    β”œβ”€β”€ _twitter-archive.scss
    β”œβ”€β”€ _work.scss
    β”œβ”€β”€ bradbice.scss
    β”œβ”€β”€ holidays.scss
    └── patterns
        β”œβ”€β”€ article__content
        β”‚   └── _article__content.scss
        β”œβ”€β”€ article__footer
        β”‚   └── _article__footer.scss
        β”œβ”€β”€ article__header
        β”‚   β”œβ”€β”€ _article__header.scss
        β”‚   └── article__header.html
        β”œβ”€β”€ article__meta
        β”‚   β”œβ”€β”€ _article__meta.html
        β”‚   └── _article__meta.scss
        β”œβ”€β”€ article__stub
        β”‚   β”œβ”€β”€ _article__stub.scss
        β”‚   β”œβ”€β”€ article__stub--blog.html
        β”‚   └── article__stub--work.html
        β”œβ”€β”€ article__tags
        β”‚   β”œβ”€β”€ _article__tags.scss
        β”‚   └── article__tags.html
        β”œβ”€β”€ aside-section
        β”‚   β”œβ”€β”€ _aside-section.html
        β”‚   └── _aside-section.scss
        β”œβ”€β”€ badge
        β”‚   └── _badge.scss
        β”œβ”€β”€ blockquote
        β”‚   β”œβ”€β”€ _blockquote.html
        β”‚   └── _blockquote.scss
        β”œβ”€β”€ breadcrumbs
        β”‚   └── _breadcrumbs.scss
        β”œβ”€β”€ button
        β”‚   β”œβ”€β”€ _button.html
        β”‚   └── _button.scss
        β”œβ”€β”€ dialog
        β”‚   └── _dialog.scss
        β”œβ”€β”€ field
        β”‚   └── _field.scss
        β”œβ”€β”€ field-group
        β”‚   └── _field-group.scss
        β”œβ”€β”€ figure
        β”‚   β”œβ”€β”€ _figure.scss
        β”‚   └── figure.html
        β”œβ”€β”€ figure__caption
        β”‚   β”œβ”€β”€ _figure__caption.scss
        β”‚   └── figure__caption.html
        β”œβ”€β”€ form
        β”‚   └── _form.scss
        β”œβ”€β”€ global-footer
        β”‚   β”œβ”€β”€ _global-footer.scss
        β”‚   └── footer.html
        β”œβ”€β”€ global-header
        β”‚   β”œβ”€β”€ _global-header.scss
        β”‚   β”œβ”€β”€ global-header--blog.html
        β”‚   └── global-header.html
        β”œβ”€β”€ global-menu
        β”‚   β”œβ”€β”€ _global-menu.scss
        β”‚   └── global-menu.html
        β”œβ”€β”€ headings
        β”‚   β”œβ”€β”€ _headings.scss
        β”‚   └── headings.html
        β”œβ”€β”€ input
        β”‚   └── _input.scss
        β”œβ”€β”€ intro
        β”‚   β”œβ”€β”€ _intro.scss
        β”‚   └── intro.html
        β”œβ”€β”€ label
        β”‚   └── _label.scss
        β”œβ”€β”€ lists
        β”‚   β”œβ”€β”€ _lists.html
        β”‚   └── _lists.scss
        β”œβ”€β”€ micro__stub
        β”‚   β”œβ”€β”€ _micro__stub.scss
        β”‚   β”œβ”€β”€ article__stub--blog.html
        β”‚   └── article__stub--work.html
        β”œβ”€β”€ page-container
        β”‚   β”œβ”€β”€ _page-container.scss
        β”‚   └── page-container.html
        β”œβ”€β”€ pagination
        β”‚   β”œβ”€β”€ _pagination.scss
        β”‚   └── pagination.html
        β”œβ”€β”€ picture
        β”‚   └── _picture.scss
        β”œβ”€β”€ plain-text
        β”‚   β”œβ”€β”€ _plain-text.scss
        β”‚   └── plain-text.html
        β”œβ”€β”€ section
        β”‚   β”œβ”€β”€ _section.scss
        β”‚   β”œβ”€β”€ section--full.html
        β”‚   └── section.html
        β”œβ”€β”€ switch
        β”‚   └── _switch.scss
        └── tags-list
            └── _tags-list.scss

Your example shows only four. How do you know that it’s one of those four?

1 Like

Turns out I had a @forward "scss/bradbice"; in _tokens.scss which was causing the error.

Thanks for helping me iron out my Sass bugs.

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