I just figured it out. We should be using Sass Modules instead of @import. Also, this video helped me a lot: https://www.youtube.com/watch?v=CR-a8upNjJ0

When I replaced @import with @use it started working.

Answer from bprdev on Stack Overflow
🌐
webpack
webpack.js.org › loaders › sass-loader
sass-loader | webpack
Chain the sass-loader with the css-loader and the style-loader to immediately apply all styles to the DOM, or with the mini-css-extract-plugin to extract it into a separate file. Then add the loader to your webpack configuration.
🌐
Robin Wieruch
robinwieruch.de › webpack-sass
How to SASS with Webpack 5 - Setup Tutorial - Robin Wieruch
October 30, 2020 - ... module.exports = { ... module: { rules: [ ... { test: /\.(scss|css)$/, use: ['style-loader', 'css-loader', 'sass-loader'], }, ], }, ... }; Then in a new src/style.scss file, add some CSS with SASS specific features (e.g. nested selectors) to it: ... That’s it. From here you can use SASS in your JavaScript project which is powered by Webpack.
🌐
npm
npmjs.com › package › sass-loader
sass-loader - npm
Chain the sass-loader with the css-loader and the style-loader to immediately apply all styles to the DOM, or with the mini-css-extract-plugin to extract it into a separate file. Then add the loader to your webpack configuration.
      » npm install sass-loader
    
Published   Feb 05, 2026
Version   16.0.7
Author   J. Tangelder
🌐
webpack
webpack.js.org › loaders › css-loader
css-loader | webpack
module.exports = { module: { rules: [ { test: /\.css$/i, use: [ "style-loader", { loader: "css-loader", options: { importLoaders: 2, // 0 => no loaders (default); // 1 => postcss-loader; // 2 => postcss-loader, sass-loader }, }, "postcss-loader", "sass-loader", ], }, ], }, }; This may change in the future when the module system (i. e. webpack) supports loader matching by origin.
🌐
DEV Community
dev.to › deepanjangh › setting-up-css-and-sass-with-webpack-3cg
Setting up CSS and Sass with Webpack!! - DEV Community
November 20, 2022 - sass-loader loads a Sass/SCSS file and compiles it to CSS. Now let's update the webpack.config.js.
🌐
webpack
docs.webpack.js.org › loaders › sass-loader
sass-loader - webpack
{ test: /\.scss$/, include: path.resolve(__dirname, 'src'), use: ['style-loader', 'css-loader', 'sass-loader'] } Webpack 5 caches automatically, but you can configure it:
🌐
W3cubDocs
docs.w3cub.com › webpack~5 › loaders › sass-loader.html
Sass-loader - Webpack 5 - W3cubDocs
Webpack provides an advanced mechanism to resolve files. The sass-loader uses Sass's custom importer feature to pass all queries to the Webpack resolving engine.
Find elsewhere
🌐
Developerhandbook
developerhandbook.com › blog › webpack › how-to-configure-scss-modules-for-webpack
How to configure SCSS modules for Webpack
sass-loader is a loader for Webpack for compiling SCSS/Sass files. style-loader injects our styles into our DOM. css-loader interprets @import and @url() and resolves them. mini-css-extract-plugin extracts our CSS out of the JavaScript bundle ...
🌐
SymfonyCasts
symfonycasts.com › screencast › javascript-webpack › sass-loader
Sass with sass-loader
I love this: sass-loader will be called first, which will convert the SASS into CSS. Then, css-loader will convert that to a JavaScript object. Finally, style-loader will add the CSS to the page.
🌐
Bootstrap
getbootstrap.com › docs › 5.0 › getting-started › webpack
Webpack and bundlers · Bootstrap v5.0
// ... { test: /\.(scss)$/, use: [{ // inject CSS to page loader: 'style-loader' }, { // translates CSS into CommonJS modules loader: 'css-loader' }, { // Run postcss actions loader: 'postcss-loader', options: { // `postcssOptions` is needed for postcss 8.x; // if you use postcss 7.x skip the key postcssOptions: { // postcss plugins, can be exported to postcss.config.js plugins: function () { return [ require('autoprefixer') ]; } } } }, { // compiles Sass to CSS loader: 'sass-loader' }] } // ... Alternatively, you may use Bootstrap’s ready-to-use CSS by simply adding this line to your project’s entry point: ... In this case you may use your existing rule for css without any special modifications to webpack config, except you don’t need sass-loader just style-loader and css-loader.
🌐
LinkedIn
linkedin.com › pulse › easy-to-understand-complete-guide-loaders-webpack-5-sutradhar
An easy-to-understand complete guide to loaders in Webpack 5
February 5, 2024 - sass-loader: First, Webpack will invoke sass-loader, which will convert our SCSS code to CSS.
🌐
W3cubDocs
docs.w3cub.com › webpack › loaders › sass-loader
Sass-loader - Webpack - W3cubDocs
Loads a Sass/SCSS file and compiles it to CSS. Use the css-loader or the raw-loader to turn it into a JS module and the MiniCssExtractPlugin to extract it into a separate file. Looking for the webpack 1 loader?
🌐
Openbase
openbase.com › js › sass-loader › versions
sass-loader: Versions | Openbase
Breaking (for resolve-url-loader only): Improve source map support. #374 ... Fix bug where multiple compilations interfered with each other. #369 ... Breaking: Remove synchronous compilation support. #334 · Breaking: Remove official node-sass@3 and webpack@1 support. 5a6bcb96d8bd7a7a11c33252ba739ffe09ca38c5...
🌐
Reddit
reddit.com › r/reactjs › sass-loader is breaking old project (webpack issue?)
r/reactjs on Reddit: sass-loader is breaking old project (webpack issue?)
August 31, 2021 -

Edit: Fixed - installed webpack manually and downgraded to webpack 4.44.2. Solution from: https://github.com/facebook/create-react-app/issues/11631

I created a react app project ealrier in the year without sass-loader, I wanted to implement it now but this is the Error I am receiving when I try to implement sass-loader and do npm start. Why is it happening?

> react-scripts start


There might be a problem with the project dependency tree.
It is likely not a bug in Create React App, but something you need to fix locally.

The react-scripts package provided by Create React App requires a dependency:

  "webpack": "4.44.2"

Don't try to install it manually: your package manager does it automatically.
However, a different version of webpack was detected higher up in the tree:

  C:\MyCode\redditProject\node_modules\webpack (version: 5.65.0)

Manually installing incompatible versions is known to cause hard-to-debug issues.

If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That will permanently disable this message but you might encounter other issues.

To fix the dependency tree, try following the steps below in the exact order:

  1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
  2. Delete node_modules in your project folder.
  3. Remove "webpack" from dependencies and/or devDependencies in the package.json file in your project folder.
  4. Run npm install or yarn, depending on the package manager you use.

I have followed the steps, but to no avail.

I can run this project if I did not have the dependencies listed below (sass-loader, css-loader, style-loader, file-loader) and if I did not include the webpack.config.js here:

module.exports = {
    module: {
        rules: [
            {
                test: /\.s[ac]ss$/i,
                use: [
                    // Creates `style` nodes from JS strings
                    "style-loader",
                    // Translates CSS into CommonJS
                    "css-loader",
                    // Compiles Sass to CSS
                    "sass-loader",
                ],
            },
            {
                test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
                use: [
                    {
                        loader: "file-loader",
                        options: {
                            name: "[name].[ext]",
                            outputPath: "fonts/",
                        },
                    },
                ],
            },
        ],
    },
};

Package.json

{
  "name": "reddit",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.10",
    "@testing-library/react": "^11.2.6",
    "@testing-library/user-event": "^12.8.3",
    "@types/jest": "^26.0.22",
    "@types/lodash": "^4.14.168",
    "@types/node": "^12.20.7",
    "@types/react": "^17.0.37",
    "@types/react-dom": "^17.0.3",
    "@types/react-router-dom": "^5.1.7",
    "css-loader": "^6.5.1",
    "embla-carousel": "^4.3.2",
    "file-loader": "^6.2.0",
    "history": "^4.10.1",
    "lodash": "^4.17.21",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-icons": "^4.2.0",
    "react-redux": "^7.2.3",
    "react-router-dom": "^5.2.0",
    "react-scripts": "4.0.3",
    "react-spring": "^9.0.0",
    "react-use": "^17.2.1",
    "redux": "^4.0.5",
    "redux-devtools-extension": "^2.13.9",
    "redux-thunk": "^2.3.0",
    "sass-loader": "^10.2.0",
    "style-loader": "^3.3.1",
    "typescript": "^4.2.3",
    "web-vitals": "^1.1.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "node-sass": "^6.0.1"
  }
}
🌐
GitHub
github.com › webpack-contrib › sass-loader › releases
Releases · webpack/sass-loader
Compiles Sass to CSS. Contribute to webpack/sass-loader development by creating an account on GitHub.
Author   webpack
🌐
Taylor Callsen
taylor.callsen.me › using-webpack-5-and-sass-with-wordpress
Using Webpack 5 and SASS with WordPress - Taylor Callsen
const path = require('path'); // css extraction and minification const MiniCssExtractPlugin = require("mini-css-extract-plugin"); const CssMinimizerPlugin = require("css-minimizer-webpack-plugin"); // clean out build dir in-between builds const { CleanWebpackPlugin } = require('clean-webpack-plugin'); module.exports = [ { entry: { 'main': [ './js/src/main.js', './css/src/main.scss' ] }, output: { filename: './js/build/[name].min.[fullhash].js', path: path.resolve(__dirname) }, module: { rules: [ // js babelization { test: /\.(js|jsx)$/, exclude: /node_modules/, loader: 'babel-loader' }, // sas
🌐
npm
npmjs.com › package › fast-sass-loader
fast-sass-loader - npm
fast sass loader for webpack. 5~10 times faster than sass-loader, and support url resolve.
      » npm install fast-sass-loader
    
Published   Nov 18, 2021
Version   2.0.1
Author   yibn2008
🌐
webpack
webpack.docschina.org › loaders › sass-loader
sass-loader | webpack 中文文档 - 印记中文
Webpack 5 现已正式发布。请阅读我们的 发布公告。如还未准备升级,请阅读 webpack 4 文档。 ... sass-loader 需要预先安装 Dart Sass 或 Node Sass(可以在这两个链接中找到更多的资料)。这可以控制所有依赖的版本, 并自由的选择使用的 Sass 实现。