Try this. I have tested it. Worked well for me.

{
    test: /\.(sa|sc|c)ss$/,
    use: [
            {
                loader: 'style-loader',
                options: {
                    hmr: true
                }
            },
            {
                loader: 'css-loader',
                options: {
                   modules: true,
                   importLoaders: 1,
                   localIdentName: '[name]__[local]___[hash:base64:5]',
                },
           },
           {
               loader: 'postcss-loader',
               options: {
                   plugins: [autoprefixer({ browsers: ['> 1%'] })]
               },
            },
            'sass-loader'
        ],
}

Also small advice: don't use 'last 3 versions' like this: plugins: [autoprefixer({ browsers: ['last 3 versions'] })] it will include a lot of dead browsers. Check it here.

'> 1%' is better

Answer from Arseniy-II on Stack Overflow
🌐
webpack
webpack.js.org › loaders › sass-loader
sass-loader | webpack
type sassOptions = | import("sass").LegacyOptions<"async"> | (( content: string | Buffer, loaderContext: LoaderContext, meta: any, ) => import("sass").LegacyOptions<"async">); ... Options for Dart Sass or Node Sass implementation. ... The charset option is true by default for dart-sass. We strongly discourage setting this to false because webpack doesn't support files other than utf-8.
🌐
GitHub
github.com › webpack-contrib › sass-loader › issues › 760
`data` option no longer supported in `sassOptions` · Issue #760 ...
August 4, 2019 - The first log was for loaderOptions while the second is for options, as shown here when i started the webpack-dev-server (note that there are 4 components importing their own sass styles): loaderOptions { sassOptions: { data: '@import "noop";', includePaths: [ '/Volumes/projects/storybook/src/sass-noop' ] } } options { data: '.App {\n\n}\n', includePaths: [ '/Volumes/projects/storybook/src/sass-noop', '/Volumes/projects/storybook/src/storybook/components' ], sourceMap: '/Volumes/projects/storybook/sass.map', sourceMapRoot: '/Volumes/projects/storybook', omitSourceMapUrl: true, sourceMapContent
Author   Smolations
Top answer
1 of 3
16

Try this. I have tested it. Worked well for me.

{
    test: /\.(sa|sc|c)ss$/,
    use: [
            {
                loader: 'style-loader',
                options: {
                    hmr: true
                }
            },
            {
                loader: 'css-loader',
                options: {
                   modules: true,
                   importLoaders: 1,
                   localIdentName: '[name]__[local]___[hash:base64:5]',
                },
           },
           {
               loader: 'postcss-loader',
               options: {
                   plugins: [autoprefixer({ browsers: ['> 1%'] })]
               },
            },
            'sass-loader'
        ],
}

Also small advice: don't use 'last 3 versions' like this: plugins: [autoprefixer({ browsers: ['last 3 versions'] })] it will include a lot of dead browsers. Check it here.

'> 1%' is better

2 of 3
4

You can write different rules for css and scss files where u can remove sass loader for css files.

test: /\.scss$/,
use: [
  {
    loader: 'style-loader',
    options: {
      hmr: true
    }
  },
  {
    loader: 'css-loader',
    options: {
      modules: true,
      importLoaders: 1,
      localIdentName: '[name]__[local]___[hash:base64:5]'
    }
  },
  {
    loader: 'sass-loader'
  },
  {
    loader: 'postcss-loader',
    options: {
      plugins: [autoprefixer({ browsers: ['last 3 versions'] })]
    }
  }
]


test: /\.css$/,
use: [
  {
    loader: 'style-loader',
    options: {
      hmr: true
    }
  },
  {
    loader: 'css-loader',
    options: {
      modules: true,
      importLoaders: 1,
      localIdentName: '[name]__[local]___[hash:base64:5]'
    }
  },
//removed sass loader
  {
    loader: 'postcss-loader',
    options: {
      plugins: [autoprefixer({ browsers: ['last 3 versions'] })]
    }
  }
]

Below is my personal setup for css & scss files

webpack.config.js

{
                test: /\.css$/,
                exclude: /node_modules/,
                use: [
                    {
                        loader: 'style-loader',
                    },
                    {
                        loader: 'css-loader',
                        options: {
                            sourceMap: true,
                            importLoaders: 2,
                        },
                    },
                    {
                        loader: 'resolve-url-loader',
                    },
                    {
                        loader: 'postcss-loader',
                        options: {
                            sourceMap: true,
                        },
                    },
                ],
            },
            {
                test: /\.scss$/,
                exclude: /node_modules/,
                use: [
                    {
                        loader: 'style-loader',
                    },
                    {
                        loader: 'css-loader',
                        options: {
                            sourceMap: true,
                            importLoaders: 3,
                        },
                    },
                    {
                        loader: 'resolve-url-loader',
                    },
                    {
                        loader: 'postcss-loader',
                        options: {
                            sourceMap: true,
                        },
                    },
                    {
                        loader: 'sass-loader',
                        options: {
                            sourceMap: true,
                        },
                    },
                ],
            },

postcss.config.js

module.exports = {
    plugins: [
        require('postcss-cssnext')({
            warnForDuplicates: false,
            features: {
                customProperties: false,
            },
        }),
        require('postcss-flexbugs-fixes')(),
        process.env.NODE_ENV === 'production'
            ? require('cssnano')({
                    preset: 'default',
              })
            : '',
    ],
};
🌐
GitHub
github.com › webpack-contrib › sass-loader › blob › master › src › options.json
sass-loader/src/options.json at main · webpack/sass-loader
Compiles Sass to CSS. Contribute to webpack/sass-loader development by creating an account on GitHub.
Author   webpack
🌐
Medium
medium.com › @bogna.ka › working-with-webpack-and-styles-a7a2f31ee6b4
Webpack and Sass
February 28, 2017 - Webpack and Sass Webpack is a module bundler very often used in latest JavaScript applications. I think it is a great tool if you want to start development quickly with minimum setup. However, when I …
🌐
GitHub
github.com › webpack-contrib › sass-loader › issues › 954
How to set `quietDeps` option for dart-sass · Issue #954 · ...
May 24, 2021 - const sassLoader = { loader: 'sass-loader', options: { sassOptions: { quietDeps: true, }, }, };
Published   May 24, 2021
Author   gcangussu
🌐
Robin Wieruch
robinwieruch.de › webpack-sass
How to SASS with Webpack 5 - Setup Tutorial
Learn how to use SASS in a Webpack powered JavaScript application ...
Find elsewhere
🌐
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 - One of the most fundamental parts of frontend development is styling, in this post, we will see how to use styles with webpack. This post is a continuation of my earlier post where I have explained How to set up react project with webpack and babel.
🌐
GitHub
github.com › webpack-contrib › sass-loader
GitHub - webpack/sass-loader: Compiles Sass to CSS · GitHub
type sassOptions = | import("sass").LegacyOptions<"async"> | (( content: string | Buffer, loaderContext: LoaderContext, meta: any, ) => import("sass").LegacyOptions<"async">); ... Options for Dart Sass or Node Sass implementation. ... The charset option is true by default for dart-sass. We strongly discourage setting this to false because webpack doesn't support files other than utf-8.
Starred by 3.9K users
Forked by 428 users
Languages   JavaScript 80.2% | SCSS 8.9% | Sass 8.8% | HTML 1.8% | CSS 0.3%
🌐
Netlify
competent-wiles-ed53ea.netlify.app › loaders › sass-loader
sass-loader
Bundling CSS with webpack has some nice advantages like referencing images and fonts with hashed urls or hot module replacement in development. In production, on the other hand, it's not a good idea to apply your style sheets depending on JS execution. Rendering may be delayed or even a FOUC ...
🌐
Developerhandbook
developerhandbook.com › blog › webpack › how-to-configure-scss-modules-for-webpack
How to configure SCSS modules for Webpack
This post explores how to configure Webpack to support standard SCSS (your-styles.scss) and SCSS modules (your-component.module.scss).
🌐
GitHub
github.com › webpack › sass-loader › tree › v12.6.0
GitHub - webpack/sass-loader at v12.6.0 · GitHub
sassOptions · sourceMap · additionalData · webpackImporter · warnRuleAsWarning · Type: type implementation = object | string; Default: sass · The special implementation option determines which implementation of Sass to use. By default the loader resolve the implementation based on your dependencies.
Starred by 3.9K users
Forked by 427 users
Languages   JavaScript 80.2% | SCSS 8.9% | Sass 8.8% | HTML 1.8% | CSS 0.3%
🌐
W3cubDocs
docs.w3cub.com › webpack › loaders › sass-loader
Sass-loader - Webpack - W3cubDocs
Bundling CSS with webpack has some nice advantages like referencing images and fonts with hashed urls or hot module replacement in development. In production, on the other hand, it's not a good idea to apply your style sheets depending on JS execution. Rendering may be delayed or even a FOUC ...
Top answer
1 of 6
35

To hide the warnings, update your vite.config.js like this:

export default defineConfig({
  css: {
    preprocessorOptions: {
      scss: {
        quietDeps: true
      }
    }
  }
})

UPDATE: a critical requirement is that you have your paths relative to node_modules or another folder that SCSS is considering to hold external modules. These folders can be listed in loadPaths scss option (node_modules is included by default, at least when SCSS is run from Vite). And not relative to current file!

E.g. this path works - all warnings are excluded:

@forward 'spinkit/scss/spinners/7-three-bounce.scss';

This path doesn't work - all warnings are shown:

@forward '../../node_modules/spinkit/scss/spinners/7-three-bounce.scss';

This requirement can be understood by reading SCSS quietDeps option description.

2 of 6
22

A fresh solution for those who are looking for a way to fix the warning in Vite:

Deprecation Warning: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0.

The quietDeps: true rule mentioned above does not work for this warning.

The most preferable way is to make Vite to use modern API for SASS:

    vite: {
        css: {
            preprocessorOptions: {
                scss: {
                    api: 'modern-compiler', // or 'modern'
                },
            },
        },
    },

Vite docs: css.preprocessorOptions

But if you want to just silence deprecation warnings, use silenceDeprecations option:

    vite: {
        css: {
            preprocessorOptions: {
                scss: {
                    silenceDeprecations: ['legacy-js-api'],
                },
            },
        },
    },

SASS docs for silenceDeprecations SASS Deprecations list

Both solutions work on Vite 5.4.6, and Sass 1.79.1

🌐
webpack
webpack.docschina.org › loaders › sass-loader
webpack 官方中文文档
module.exports = { module: { rules: [ { test: /\.s[ac]ss$/i, use: [ "style-loader", "css-loader", { loader: "sass-loader", options: { implementation: require("sass"), sassOptions: { fiber: require("fibers"), }, }, }, ], }, ], }, }; 类型:Object|Function 默认值:Sass 实现的默认值 ... ℹ 我们推荐不要设置 outFile,sourceMapContents,sourceMapEmbed,sourceMapRoot 这些选项,因为当 sourceMap 是 true 时,sass-loader 会自动设置这些选项。 · ℹ️ 可以使用 this.webpackLoaderContext 属性访问自定义 importer 中的 loader 上下文。
🌐
npm
npmjs.com › package › sass-loader
sass-loader - npm
Finally run webpack via your preferred method (e.g., via CLI or an npm script). For production mode, the style (new API, by default since 16 version) and outputStyle (old API) options default to compressed unless otherwise specified in sassOptions.
      » npm install sass-loader
    
Published   Feb 05, 2026
Version   16.0.7
Author   J. Tangelder
🌐
Vue Loader
vue-loader.vuejs.org › guide › pre-processors.html
Using Pre-Processors | Vue Loader
// webpack.config.js -> module.rules { test: /\.sass$/, use: [ 'vue-style-loader', 'css-loader', { loader: 'sass-loader', options: { indentedSyntax: true, // sass-loader version >= 8 sassOptions: { indentedSyntax: true } } } ] } sass-loader also supports a additionalData option which allows you to share common variables among all processed files without having to explicit import them: // webpack.config.js -> module.rules { test: /\.scss$/, use: [ 'vue-style-loader', 'css-loader', { loader: 'sass-loader', options: { // you can also read from a file, e.g.