I am working on a pod-style ember app that uses ember-cli-sass, and ember-component-css.
I defined a variable in app/styles/app.scss that looks like this:
$yellow: #f2d173;
But when I try to use that variable in the scss file of a component located at: app/components/login-form/styles.scss, I get an error that reads:
Error: Undefined variable.
I would have expected the app.scss file to get loaded first, and for my variable to be accessible within my components - but something is not working perfectly.
Does any one know how to get application-wide scss/sass variables to be accessible in my components?
Could be a problem with including the file(s) / passing the var ... some more Infos about your project organization would help ...
How do you organize/include your modules/files (
@importor new rule@use)?How is the file/dicrectory structure of your project?
If you work the traditional way with
@importthe order of importing the files/modules to the main file is important. You may check:@import:Is
.../login-form/styles.scssimported to the main.scss AFTER the variable is set inapp/styles/app.scss?(If you are using ember pod style css files, you are probably importing your
login-form's styles from@import "pod-styles";, ensure that your variable definition is before that line!)If you indeed work with new technique
@useit is another way round and can be a little bit tricky. You may check:If
@use:Is the file where the variable is set (
app/styles/app.scss)@use'd to.../login-form/styles.scsswhere you need the variable?Alertnative if
@use: If the moduleapp/components/login-form/styles.scssis@use'd itself, did you pass your variable to the module when you@useit?As
@useis new, here ar some more infos about how it works: https://sass-lang.com/documentation/at-rules/use.