Strangely, the loadPaths attribute doesn't work, what worked for me was using includePaths:
{
loader: 'sass-loader',
options: {
sassOptions: {
includePaths: [path.resolve(__dirname, 'Develop', 'Styles')]
}
}
}
Answer from violetflare on Stack Overflow
» npm install sass-loader
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]
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 thesassOptionsoption. Thefunctionsoption can't be used as Function, you should usesassOptionas Function to achieve this. - the
dataoption was renamed to theprependDataoption
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";`
}
}
}
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.
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