Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getting "@use rules must be written before any other rules" error even though config has hoistUseStatements #150

Open
patrick99e99 opened this issue Nov 3, 2021 · 10 comments

Comments

@patrick99e99
Copy link

I have an icons.scss file which has in it:

@use '~fancy_icons/dist/index' as i;
$icons: i.$icons;
...

And my config has:

loaders.push({
  loader: 'sass-resources-loader',
  options: {
    hoistUseStatements: true,
    resources: [
      'app/javascript/stylesheets/icons.scss',
    ]
  }
});

Yet I still get:

Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
ModuleBuildError: Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: @use rules must be written before any other rules.
    ╷
402 │ @use '~fancy_icons/dist/index' as i;
    │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@AmirMasoud-Beheshti
Copy link

No fix yet?
I have the exact same issue

@justin808
Copy link
Member

I'm open to a PR!

@mrleblanc101
Copy link

mrleblanc101 commented May 13, 2022

Still an issue.
The node-sass vs dart-sass really took a toll on sass :/

@mrleblanc101
Copy link

I have @use "sass:math"; in 2 files. One is settings/_svg-uri.scss and one is settings/_functions.scss
Here is my config.

options: {
    hoistUseStatements: true,
    resources: ['@/assets/scss/settings/*'],
}

This would expand to this:
Capture d’écran, le 2022-05-13 à 16 06 56
But I get this error:

Module build failed. SassError: @use rules must be written before any other rules.

I shouldn't get any error because of the hosting, but I still get one.

I have a weird workaround, I remove the hosting (which make no sense) and manually move one of my file with @use "sass:math"; as the first element before the import glob (had the move it to another folder).

options: {
    resources: ['@/assets/scss/functions/svg-uri', '@/assets/scss/settings/*'],
}

Capture d’écran, le 2022-05-13 à 16 10 09

I don't understand why there is no error now because there is at leant one @use "sass:math"; which is not at the begging because other file are loaded in between.

@justin808
Copy link
Member

I'm still open for code and doc PRs!

@mrleblanc101
Copy link

I don't know what the problem is and I can't say I understand how this plugin work, sorry.

@mrleblanc101
Copy link

mrleblanc101 commented May 17, 2022

Ok, I'm dumb. It still doesn't work.
My import was incorrect '@/assets/scss/functions/svg-uri' instead of '@/assets/scss/functions/_svg-uri.scss' and it failed silently.
But I think I understand what the problem is.
I have a @use "sass:math"; in 2 files. I should only have it in the file that is imported first.

  1. Shouldn't this library deduplicate the @use statement ?
  2. Shouldn't the webpack build fail it a file cannot be found ? See my exemple above.

@nikkifurls
Copy link

I'm experiencing this as well with @use 'sass:math'. Is there any update here? Does hoistUseStatements not work correctly or are we doing something wrong?

@tannerhuynh
Copy link

Bump still having this issue. Any progress?

@justin808
Copy link
Member

I'm open to reviewing a PR.

Another option is that you can hire ShakaCode to address this issue, and we can help you with many other issues.

See shakacode.com and especially https://www.shakacode.com/blog/client-engagement-model/.

If you're interested, please book a time with me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants