In my Next.js Application, I have a global CSS file named main.scss
imported in the pages/_app.js
file.
_app.js
import '../global-styles/main.scss'
export default function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />
}
The styles from this global file work perfectly.
I also have modular SCSS files attached to components, using the naming convention [component].module.scss.
In one of the files that I import into main.scss
, specifically variables.scss
, I have defined a variable.
variables.scss
$mobile: 750px;
main.scss
@import './fonts.scss';
@import './variables.scss';
@import './global.scss';
However, when I attempt to use this variable in one of my modular CSS files, I encounter an error.
./module-styles/navbar.module.scss (./node_modules/css-loader/dist/cjs.js??ref--5-oneOf-3-1!./node_modules/postcss-loader/src??__nextjs_postcss!./node_modules/resolve-url-loader??ref--5-oneOf-3-3!./node_modules/sass-loader/dist/cjs.js??ref--5-oneOf-3-4!./module-styles/navbar.module.scss)
SassError: Undefined variable: "$mobile".
on line 19 of /Users/Parv/Documents/reactx/module-styles/navbar.module.scss
>> @media (max-width: $mobile) {
---------------------------^
My concern is, why are the global variables I declare in my main.scss file not being recognized?