Sass Loader报错:ValidationError: Invalid options object. Sass Loader has been initialised using an opt

Posted xifeng59

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Sass Loader报错:ValidationError: Invalid options object. Sass Loader has been initialised using an opt相关的知识,希望对你有一定的参考价值。

在vue.config.js中引入sass全局配置后报错
vue.config.js代码如下:
module.exports = {
  devServer: {
    port: 3333,
    open: true
  },
  css: {
    loaderOptions: {
      sass: {
        data: `@import "@/assets/scss/_variable.scss";`
      }
    }
  }
}

_variable.scss的代码如下:

$theme-color: #33aef0;

组件中的scss代码如下:

<style lang="scss">
#app {
  color: $theme-color;
  height: 100vh;
}
</style>

页面报错如下:

./src/assets/scss/reset.scss (./node_modules/css-loader/dist/cjs.js??ref--8-oneOf-3-1!./node_modules/postcss-loader/src??ref--8-oneOf-3-2!./node_modules/sass-loader/dist/cjs.js??ref--8-oneOf-3-3!./src/assets/scss/reset.scss)
Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
ValidationError: Invalid options object. Sass Loader has been initialised using an options object that does not match the API schema.
 - options has an unknown property ‘data‘. These properties are valid:
   object { implementation?, sassOptions?, prependData?, sourceMap?, webpackImporter? }
    at validate (E:element-uivue-manage-system
ode_modulesschema-utilsdistvalidate.js:85:11)
    at Object.loader (E:element-uivue-manage-system
ode_modulessass-loaderdistindex.js:36:28)
解决办法:
将data改成
prependData
// 旧
data: `@import "~@/assets/scss/variables.scss";`
// 新
prependData: `@import "~@/assets/scss/variables.scss";`

以上是关于Sass Loader报错:ValidationError: Invalid options object. Sass Loader has been initialised using an opt的主要内容,如果未能解决你的问题,请参考以下文章

Sass Loader报错:ValidationError: Invalid options object. Sass Loader has been initialised using an opt

Vue中安装sass依赖,style引用出现报错。sass-loader高版本的坑

Vue中安装sass依赖,style引用出现报错。sass-loader高版本的坑

sass-loader报错UnhandledPromiseRejectionWarning: TypeError: resolverFactory is not a function

node-sass安装失败,并且报错Module build failed (from ./node_modules/sass-loader/lib/loader.js)

vue cli3使用官方方法配置sass全局变量报错ValidationError: Invalid options object. Sass Loader has been initialised