Im currently working on a react project and im using sass. When im starting the project everything works and i can see that the variables that i defined are being used correctly. Even so when im starting the app or just saving and getting a new render the screen is filled with a bunch of errors like this one:
Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: Undefined variable.
╷
9 │ background-color: $clr1;
│ ^^^^^
╵
src\assets\scss\basics\_buttons.scss 9:23 root stylesheet
styles.scss
// setup
@import "./setup/variables";
@import "./setup/functions";
@import "./setup/mixins";
@import "./setup/layout";
// basics
@import "./basics/helpers";
@import "./basics/base";
@import "./basics/buttons";
// cmps
@import "./cmps/back-button";
@import "./cmps/footer";
@import "./cmps/header";
@import "./cmps/selected-quotes";
//views
@import "./views/about";
@import "./views/homepage";
@import "./views/share";
@import "./views/story-check";
@import "./views/template-edit2";
@import "./views/testimony";
@import "./views/story-upload";
//QUOTE
@import "./cmps/quote/quote-preview";
@import "./cmps/quote/quote-list";
@import "./cmps/quote/quote-tags";
@import "./cmps/quote/quote-toolbar";
@import "./cmps/quote/quote-filter";
@import "./cmps/quote/paging/paging";
_variables.scss
// colors
$clr1: #CD531F;
$clr2: #a7c6d3;
$clr3: #3F3F3F;
// layouts
$layoutPadding: 20px;
// breakpoints
$break-narrow: 490px;
$break-585: 585px;
$break-normal: 760px;
$break-wide: 960px;
$padded-break-narrow: $break-narrow+$layoutPadding * 2;
$padded-break-normal: $break-normal+$layoutPadding * 2;
$padded-break-wide: $break-wide+$layoutPadding * 2;
_buttons.scss
button {
cursor: pointer;
}
.primary-btn {
padding: 16px;
background-color: $clr1;
color: white;
border-radius: 4px;
border: none;
font-weight: bold;
font-size: rem(14px);
&:hover {
background-color: $clr1;
color: white;
}
}
index.js(where i import the main styles file)
import React from 'react';
import ReactDOM from 'react-dom/client';
import { BrowserRouter as Router } from 'react-router-dom';
import { Provider } from 'react-redux';
import { store } from './store/store'
import './assets/scss/styles.scss'
// import reportWebVitals from './reportWebVitals';
import { RootCmp as App } from './root-cmp'
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<Provider store={store}>
<Router>
<App />
</Router>
</Provider>
)
Here are the things that i have tried:
- importing the styles file in the App component
- checked all the file names(all of them have _ at the begining)
- made sure _variables.scss is imported at the top of styles.scss
one thing that did work: when i import _variables.scss inside _buttons.scss there are no errors but i dont want to have to import the variables file everutime i want to use a variable.
Any suggestions??