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

Unable to use Sass built-in modules #143

Closed
markhorgan opened this issue Feb 2, 2021 · 29 comments
Closed

Unable to use Sass built-in modules #143

markhorgan opened this issue Feb 2, 2021 · 29 comments

Comments

@markhorgan
Copy link

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.

@leevihuhtamaa
Copy link

I can confirm this issue and looking for a solutions :(

@leevihuhtamaa
Copy link

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.

@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?

@dcrabbeYapily
Copy link

dcrabbeYapily commented May 21, 2021

any solution to this would be great.

ERROR in ./components/Navigation.vue?vue&type=style&index=0&id=9fda8526&lang=scss&scoped=true& (./node_modules/css-loader/dist/cjs.js??ref--7-oneOf-1-1!./node_modules/vue-loader/lib/loaders/stylePostLoader.js!./node_modules/postcss-loader/src??ref--7-oneOf-1-2!./node_modules/sass-loader/dist/cjs.js??ref--7-oneOf-1-3!./node_modules/sass-resources-loader/lib/loader.js??ref--7-oneOf-1-4!./node_modules/vue-loader/lib??vue-loader-options!./components/Navigation.vue?vue&type=style&index=0&id=9fda8526&lang=scss&scoped=true&)
Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: Invalid Sass identifier "sass:math"
  ╷
2 │ @use '../assets/styles/sass:math';
  │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ╵

@ehainer
Copy link

ehainer commented May 24, 2021

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:

build: {
  extend(config, { loaders }){
    loaders.scss.additionalData = '@use "sass:math";'
  }
}

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.

@andrey-hohlov
Copy link

andrey-hohlov commented Jun 5, 2021

https://github.com/shakacode/sass-resources-loader has hoistUseStatements options to handle this case

@rchl
Copy link
Collaborator

rchl commented Jun 5, 2021

👍

@rchl rchl closed this as completed Jun 5, 2021
@rchl
Copy link
Collaborator

rchl commented Jun 5, 2021

Support for that was added in v1.1.0 through #162

@botteu
Copy link

botteu commented Jun 10, 2021

I cannot get this to work. Either I get SassError: @use rules must be written before any other rules. or when I use hoistUseStatements: true I get errors like SassError: 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...

@rchl
Copy link
Collaborator

rchl commented Jun 10, 2021

Create a reproduction repo and someone will probably be able to help you.

@leevihuhtamaa
Copy link

Support for that was added in v1.1.0 through #162

Thanks @rchl ! Works like a charm

@riddla
Copy link

riddla commented Jun 28, 2021

@rchl
Copy link
Collaborator

rchl commented Jun 29, 2021

@riddla try removing yarn.lock and node_modules and re-run yarn.

@provok-me
Copy link

@riddla try removing yarn.lock and node_modules and re-run yarn.

Having the same problem. Removing yarn.lock and node_modules didn't resolve the issue.

@provok-me
Copy link

@riddla did you found a hack for this?

@provok-me
Copy link

provok-me commented Jul 11, 2021

@rchl Having only one file using @useand @forwardstatements seems to work.

The problem comes when I import multiple files that use @use or @forward. Even when using hoistUseStatements: true.

@rchl
Copy link
Collaborator

rchl commented Jul 11, 2021

Please create reproduction

@provok-me
Copy link

I'm not able to create a reproduction. Codesandbox is shit.

With the Nuxt's codesandbox template I'm not even able to use lang="scss" in a component... "sass-loader not found in /sandbox" even after installing it 😂

I don't have time to battle with a fake environment.

What I can tell you is that I use:

  • "@nuxtjs/style-resources": "^1.2.0",
  • "nuxt": "^2.15.0"
  • "sass": "^1.35.2",

@rchl
Copy link
Collaborator

rchl commented Jul 11, 2021

You can create a repo locally and push it to GitHub

@provok-me
Copy link

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 :

  1. create-nuxt-app
  2. install @nuxtjs/style-resources and sass
  3. create multiple scss files
  4. use hoistUseStatements: true
  5. in all those files use sass:string, sass:map, etc. and create dummy functions (at least one @use per file)
  6. run your Nuxt app
  7. debug

@rchl
Copy link
Collaborator

rchl commented Jul 11, 2021

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.

@riddla
Copy link

riddla commented Jul 12, 2021

@rchl What about the two reproductions on CodeSandbox that I posted above?
(Removing yarn.lock and node_modules did also not do the trick for me locally.)

@rchl
Copy link
Collaborator

rchl commented Jul 12, 2021

@rchl What about the two reproductions on CodeSandbox that I posted above?
(Removing yarn.lock and node_modules did also not do the trick for me locally.)

It did help here when I've tried it

@provok-me
Copy link

provok-me commented Jul 12, 2021

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.

Here I created a repo @rchl.
https://github.com/Alphability/multiple-use-statements

Same problem.

It seems to come from using style-resources and Nuxt css property with scss files using @use statements.

@rchl
Copy link
Collaborator

rchl commented Jul 13, 2021

Might be some case that is not handled by sass-resources-loader but what you could do is create a small SCSS wrapper file like app.scss with

@import 'constants';
@import 'functions';
@import 'mixins';

and import that instead.

@provok-me
Copy link

Might be some case that is not handled by sass-resources-loader but what you could do is create a small SCSS wrapper file like app.scss with

@import 'constants';
@import 'functions';
@import 'mixins';

and import that instead.

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 @use rules.

Thanks @rchl!

@mahish
Copy link

mahish commented Jul 30, 2021

Temporary fix shakacode/sass-resources-loader#148

@rchl
Copy link
Collaborator

rchl commented Aug 1, 2021

Using single quotes instead of double quotes doesn't fix the reproduction above. At least not fully, so there is likely another issue in the loader.

Feel free to report an issue there if it's important for you.

@tophermurphy
Copy link

Still having this issue.

@Asef00
Copy link

Asef00 commented Jun 22, 2022

In my case fixed by:

  • Using hoistUseStatements: true
  • Wrapping all resources(variables & mixins) into a single SCSS file with @use 'sass:math'; in the first line.

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

No branches or pull requests