You need to separate your functions, variables & mixins from actual CSS rules.

These files will be imported and available to every component you write, which is great for things like variables, functions, or mixins, but you should avoid any actual CSS rules. Adding CSS rules to your shared Sass files will import those rules into every component and bloat your project. For global CSS rules, create a separate file and import it into your main App.vue file instead.

Source: https://austingil.com/global-sass-vue-project/

Answer from mstroiu on Stack Overflow
🌐
webpack
webpack.js.org › loaders › sass-loader
sass-loader | webpack
Add the missing URL rewriting using the resolve-url-loader. Place it before sass-loader in the loader chain. Library authors usually provide a variable to modify the asset path. bootstrap-sass for example, has an $icon-font-path. implementation · sassOptions · sourceMap · additionalData ·
🌐
Vue Loader
vue-loader.vuejs.org › guide › pre-processors.html
Using Pre-Processors | Vue Loader
sass-loader also supports a additionalData option which allows you to share common variables among all processed files without having to explicit import them:
🌐
npm
npmjs.com › package › sass-loader
sass-loader - npm
Add the missing URL rewriting using the resolve-url-loader. Place it before sass-loader in the loader chain. Library authors usually provide a variable to modify the asset path. bootstrap-sass for example, has an $icon-font-path. implementation · sassOptions · sourceMap · additionalData ·
      » npm install sass-loader
    
Published   Feb 05, 2026
Version   16.0.7
Author   J. Tangelder
🌐
GitHub
github.com › webpack › webpack › discussions › 17612
sass-loader additionalData not working for sass variable [SassError: Undefined variable.] · webpack/webpack · Discussion #17612
module.exports = { module: { rules: [ { test: /\.s[ac]ss$/i, use: [ "style-loader", "css-loader", { loader: "sass-loader", options: { additionalData: "$env-color: " + process.env.ENV_COLOR + ";", }, }, ], }, ], }, }; .env contains: ENV_COLOR='#114598' App.scss: .App-link { color: $env-color; } Repo to replicate issue can be found here: https://github.com/matthieunelmes/webpack-test ·
Author   webpack
🌐
GitHub
github.com › webpack-contrib › sass-loader
GitHub - webpack/sass-loader: Compiles Sass to CSS · GitHub
Add the missing URL rewriting using the resolve-url-loader. Place it before sass-loader in the loader chain. Library authors usually provide a variable to modify the asset path. bootstrap-sass for example, has an $icon-font-path. implementation · sassOptions · sourceMap · additionalData ·
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%
Top answer
1 of 2
9

Serg already gave the answer in comment. It's worked for me. Adding the answer for others. Hope it will help others.

Just run this command

npm i sass-loader@latest
2 of 2
4

You can update your packages via using yarn upgrade-interactive --latest, in case of sass-loader, if you have upgrade it from 7 to 9, you may have some invalid options erros which you can fixed in below steps as I've explained before: https://stackoverflow.com/a/62844942/12666332

Problem

Based on https://github.com/vuejs/vue-cli/issues/4513, And If you have upgrade your sass-loader from v7 to 8 or 9, You may have faced with th validation-error for invalid options

vue.config.js(valid syntax for sass-loaderv7 in webpack)

  css: {
    loaderOptions: {
      sass: {
        data: `@import "@/assets/styles/variables/index.scss";`
      }
    }
  }

errors

object:
    ValidationError: Invalid options object. Sass Loader has been
    initialized using an options object that does not match the API schema.
      - options has an unknown property 'data'. These properties are valid:

sass-loader v8.0 Breaking Changes

You should know that v8. has below breaking changes :https://github.com/webpack-contrib/sass-loader/releases/tag/v8.0.0

  • minimum required webpack version is 4.36.0
  • minimum required node.js version is 8.9.0
  • move all sass (includePaths, importer, functions) options to the sassOptions option. The functions option can't be used as Function, you should use sassOption as Function to achieve this.
  • the data option was renamed to the prependData option default value of the sourceMap option depends on the devtool value (eval/false values don't enable source map generation)

Solution v8

As the docs says, move all sass (includePaths, importer, functions) options to the sassOptions option. The functions option can't be used as Function, you should use sassOption as Function to achieve this. the data option was renamed to the prependData option

sass-loader v9.0 Breaking Changes

You should know that v9. has below breaking changes :https://github.com/webpack-contrib/sass-loader/releases/tag/v9.0.0

  • BREAKING CHANGES minimum supported Nodejs version is 10.13
  • prefer sass (dart-sass) by default, it is strongly recommended to migrate on sass (dart-sass)
  • the prependData option was removed in favor the additionalData option, see docs
  • when the sourceMap is true, sassOptions.sourceMap, sassOptions.sourceMapContents, sassOptions.sourceMapEmbed, sassOptions.sourceMapRoot and sassOptions.omitSourceMapUrl will be ignored.

Solution v9

In ver9 as you can see in the docs https://github.com/webpack-contrib/sass-loader#options (https://github.com/webpack-contrib/sass-loader#sassoptions , https://github.com/webpack-contrib/sass-loader#additionaldata), if we change data to additionalData if will fix the invalid options errors.

  css: {
    loaderOptions: {
      sass: {
        additionalData: `@import "@/assets/styles/variables/index.scss";`
      }
    }
  }
🌐
webpack
webpack.docschina.org › loaders › sass-loader
sass-loader | webpack 中文文档 - 印记中文
Library 作者一般都会提供变量,用来设置资源路径。比如 bootstrap-sass 可以通过 $icon-font-path 进行设置。 ... 默认情况下,loader 将会根据你的依赖解析需要使用的实现。 只需将必需的实现添加到 package.json(sass 或 node-sass 包)中并安装依赖项即可。
🌐
Austin Gil
austingil.com › global-sass-vue-project
Automatically import SASS/SCSS into every Vue.js component – Austin Gil
import { fileURLToPath, URL } from 'node:url' import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' // https://vitejs.dev/config/ export default defineConfig({ plugins: [vue()], resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) } }, css: { preprocessorOptions: { scss: { additionalData: `@import "@/assets/_shared.scss";` } } } }) Create a file called vue.config.js (if you do not already have one) ... module.exports = { css: { loaderOptions: { sass: { additionalData: `@import "@/assets/_shared.scss";`, }, }, }, };
Find elsewhere
🌐
Vue School
vueschool.io › home › tutorials › globally load sass into vue.js with vite
Globally Load SASS into Vue.js with Vite - Vue School Articles
December 30, 2024 - Here’s how to set up global SASS files in Vue.js with Vite: Open or create the vite.config.js file in your project root. ... // vite.config.js import { fileURLToPath, URL } from 'node:url' import { defineConfig } from 'vite'; import vue from '@vitejs/plugin-vue'; export default defineConfig({ plugins: [vue()], css: { preprocessorOptions: { scss: { additionalData: ` @import "@/scss/_variables.scss"; @import "@/scss/_mixins.scss"; ` } } }, resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) } } });
🌐
Stack Overflow
stackoverflow.com › questions › 70392259 › webpack-make-sass-loader-additionaldata-dependent-on-the-entry-name
Webpack: make sass-loader `additionalData` dependent on the entry name - Stack Overflow
loader: "sass-loader", options: { additionalData: (content, loaderContext) => { if (CURRENT_ENTRY == 'theme1') return "@use 'theme1.scss' as vars"; else return "@use 'theme2.scss' as vars"; }, } But I can't get the current entry... any idea if this is possible or any suggestions for alternative solutions?
🌐
GitHub
github.com › webpack-contrib › sass-loader › issues › 908
SassError: This file is already being loaded (when using ...
July 26, 2020 - // webpack.config.js { test: /\.(css|scss)$/, use: [ MiniCssExtractPlugin.loader, { loader: "css-loader", options: { modules: false, importLoaders: 1 } }, "postcss-loader", { loader: "sass-loader", options: { additionalData: `@import "app/scss/themes/${theme}.scss";` } } ] }
Author   matttk
Top answer
1 of 11
121

Seems same issue like here: https://github.com/JeffreyWay/laravel-mix/issues/2206

Solution is

npm uninstall --save-dev sass-loader
npm install --save-dev [email protected]
2 of 11
49

Problem

Based on vue-cli - github issue, If you did upgrade your sass-loader from v7 to 8 or 9, You may have faced with the validation-error for invalid options :

vue.config.js(valid syntax for sass-loaderv7 in webpack)

  css: {
    loaderOptions: {
      sass: {
        data: `@import "@/assets/styles/variables/index.scss";`
      }
    }
  }

errors

object:
    ValidationError: Invalid options object. Sass Loader has been
    initialized using an options object that does not match the API schema.
      - options has an unknown property 'data'. These properties are valid:

sass-loader v8.0 Breaking Changes

You should know that v8. has below breaking changes

  • minimum required webpack version is 4.36.0
  • minimum required node.js version is 8.9.0
  • move all sass (includePaths, importer, functions) options to the sassOptions option. The functions option can't be used as Function, you should use sassOption as Function to achieve this.
  • the data option was renamed to the prependData option default value of the sourceMap option depends on the devtool value (eval/false values don't enable source map generation)

Solution v8

As the docs says:

  • move all sass (includePaths, importer, functions) options to the sassOptions option. The functions option can't be used as Function, you should use sassOption as Function to achieve this.
  • the data option was renamed to the prependData option

sass-loader v9.0 Breaking Changes

You should know that v9. has below breaking changes

  • BREAKING CHANGES minimum supported Nodejs version is 10.13
  • prefer sass (dart-sass) by default, it is strongly recommended to migrate on sass (dart-sass)
  • the prependData option was removed in favor the additionalData option, see docs
  • when the sourceMap is true, sassOptions.sourceMap, sassOptions.sourceMapContents, sassOptions.sourceMapEmbed, sassOptions.sourceMapRoot and sassOptions.omitSourceMapUrl will be ignored.

Solution v9

In ver9 as you can see in the options, sassOption , additionalData, if we change data to additionalData it will fix the invalid options errors.

  css: {
    loaderOptions: {
      sass: {
        additionalData: `@import "@/assets/styles/variables/index.scss";`
      }
    }
  }
🌐
GitHub
github.com › nrwl › nx › issues › 8659
Be able to provide additional options to sass-loader/style processor (additionalData) · Issue #8659 · nrwl/nx
October 2, 2021 - { loader: 'sass-loader', options: { additionalData: '@import \'variables\'', sassOptions: { includePaths: [ path.resolve(__dirname, 'src/main/styles'), ], quietDeps: true, }, },
Author   tomdglenn91
🌐
CSS-Tricks
css-tricks.com › how-to-import-a-sass-file-into-every-vue-component-in-an-app
How to Import a Sass File into Every Vue Component in an App | CSS-Tricks
August 13, 2020 - Reader Esteban Jelicich notes that as of sass-loader 9, data needs to be additionalData above.
🌐
Gatsby
gatsbyjs.com › plugins › gatsby-plugin-sass
gatsby-plugin-sass | Gatsby
See webpack’s sass-loader documentation for reference. ... plugins: [ { resolve: `gatsby-plugin-sass`, options: { additionalData: "$env: " + process.env.NODE_ENV + ";", }, }, ]
🌐
Vue CLI
cli.vuejs.org › guide › css.html
Working with CSS | Vue CLI
Vue CLI projects come with support for PostCSS, CSS Modules and pre-processors including Sass, Less and Stylus. All compiled CSS are processed by css-loader, which parses url() and resolves them as module requests. This means you can refer to assets using relative paths based on the local file ...
🌐
GitHub
github.com › web-infra-dev › rsbuild › issues › 2582
[Bug]: Type of sass-loader additionalData function is wrong · Issue #2582 · web-infra-dev/rsbuild
The type of additionalData function of sass plugin is · type Callback<T> = (loaderContext: Webpack.loader.LoaderContext) => T; However, there is supposed to be a content argument: // This is what the type is supposed to be type Callback<T> = (content: string, loaderContext: Webpack.loader.LoaderContext) => T; Which one is right?