After successfully styling my NextJS app with SCSS modules, I encountered an unexpected error when I returned to work on it later:
Syntax error: Invalid CSS after "...ound: variables": expected expression (e.g. 1px, bold), was ".$main-gradient-bac"
I was puzzled because I hadn't made any changes since it was running smoothly before. Following the NextJS docs' recommendation, I installed SASS using npm i sass
. The version of NextJS I am using is 9.5.1.
Here is a snippet from my package.json:
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"test": "jest"
},
"dependencies": {
//dependencies here
},
"devDependencies": {
//dev dependencies here
}
}
The issue is not restricted to just one file as commenting out this particular file triggers errors in other .scss files as well:
@use 'variables';
html,
body {
padding: 0;
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,
Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
background: variables.$main-gradient-background;
scroll-behavior: smooth;
}
a {
color: lightseagreen;
text-decoration: none;
}
button {
background-color: black;
}
//more styles...