style-resources: Unable to use Sass built-in modules
I’m using dart-sass node module but stylesheets loaded with the style resources module aren’t able to load Sass built-in modules
E.g.
abstractions/units.scss:
@use "sass:math";
nuxt.config.js:
styleResources: {
scss: [
'~/assets/scss/abstractions/*.scss',
]
},
css: [
'~/assets/scss/global.scss'
],
Results in the error:
SassError: Invalid Sass identifier “sass:math” @use “abstractions/sass:math”;
If I exclude the file from being loaded by style resources module and import it manually from my global.scss file it seems to work ok.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 18
- Comments: 29
Dude I don’t have time to create a repo, and push it to GitHub to help you debug. I’m already working on a personal projet on a Sunday. I’m not here to become a collaborator on style-resources.
You wanna reproduce :
create-nuxt-app@nuxtjs/style-resourcesandsasshoistUseStatements: truesass:string,sass:map, etc. and create dummy functions (at least one @use per file)Probably not the most ideal solution to this problem (smarter and more patient minds than I could jump in), but I managed to get this working by adding the following to my nuxt.config.js:
I could then use
math.*functions inside any *.scss file loaded from styleResources. Adjust your loader as necessary…I would be curious to know what the drawbacks to this method are, either in terms of testing/compilation time and/or app size, if any.
I cannot get this to work. Either I get
SassError: @use rules must be written before any other rules.or when I usehoistUseStatements: trueI get errors likeSassError: Invalid Sass identifier "sass:math"because the @use-statements come out like@use '../../../assets/styles/config/sass:math';. I feel like I’ve tried everthing…any solution to this would be great.
You have an issue and not me so sorry but i won’t spend time trying to reproduce it if you don’t even care enough to create a straightforward reproduction.
Even if there is an issue, it likely is in the sass-loader itself, to be fair.
I can confirm this issue and looking for a solutions 😦
Support for that was added in v1.1.0 through https://github.com/nuxt-community/style-resources-module/pull/162
It seems to be working with on file importing (w/
@import) all the other files I wanted to use w/ style-resources. In the imported files I can use@userules.Thanks @rchl!
Might be some case that is not handled by
sass-resources-loaderbut what you could do is create a small SCSS wrapper file likeapp.scsswithand import that instead.
@markhorgan how did you get this working? if i declare @use ‘sass:math’; in my ‘global.scss’ i get following error:
SassError: @use rules must be written before any other rules.Or did you just dropped styleResources completely in this scenario?