vue cli3使用官方方法配置sass全局变量报错ValidationError: Invalid options object. Sass Loader has been initialised using an options object that does not match the API schema.

我使用官方文档提供的配置sass全局变量,但是报错!

vue.config.js代码如下:

module.exports = {
    css: {
        loaderOptions: {
          sass: {
            data: `@import "[email protected]/assets/scss/variables.scss";`,
          },
        }
      }
}

variables.scss的代码如下:

$color:#fff;

组件代码如下:

<style lang="scss"  type="text/css" scope>
    // $tcolor:red;
     .title{
        position: fixed;
        left: 0;
        top: 0;
        width: 100%;
        height: 40px;
        background-color: cornflowerblue;

    } .title p {
            width: 100%;
            height: 100%;
            line-height: 40px;
            text-align: center;
            font-size: 20px;
            color: $color;
        }
</style>

报错内容如下:

 error  in ./src/components/header.vue?vue&type=style&index=0&lang=scss&scope=tr
ue&

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?, webpackImpo
rter? }
    at validate (C:\Users\Administrator\Desktop\tang\node_modules\sass-loader\no
de_modules\schema-utils\dist\validate.js:49:11)
    at Object.loader (C:\Users\Administrator\Desktop\tang\node_modules\sass-load
er\dist\index.js:36:28)

 @ ./node_modules/vue-style-loader??ref--8-oneOf-1-0!./node_modules/css-loader??
ref--8-oneOf-1-1!./node_modules/vue-loader/lib/loaders/stylePostLoader.js!./node
_modules/postcss-loader/src??ref--8-oneOf-1-2!./node_modules/sass-loader/dist/cj
s.js??ref--8-oneOf-1-3!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_
modules/vue-loader/lib??vue-loader-options!./src/components/header.vue?vue&type=
style&index=0&lang=scss&scope=true& 4:14-445 14:3-18:5 15:22-453
 @ ./src/components/header.vue?vue&type=style&index=0&lang=scss&scope=true&
 @ ./src/components/header.vue
 @ ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loade
r/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loade
r/lib??vue-loader-options!./src/App.vue?vue&type=script&lang=js&
 @ ./src/App.vue?vue&type=script&lang=js&
 @ ./src/App.vue
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?http://192.168.0.101:8080/sockjs-node (webp
ack)/hot/dev-server.js ./src/main.js

问题原因:

新版 sass-loader导致的,更换如下配置来解决:

// 旧
data: `@import "[email protected]/assets/scss/variables.scss";`
// 新
prependData: `@import "[email protected]/assets/scss/variables.scss";`

原文地址:https://www.cnblogs.com/dekevin/p/12347019.html

时间: 2024-08-29 08:52:50

vue cli3使用官方方法配置sass全局变量报错ValidationError: Invalid options object. Sass Loader has been initialised using an options object that does not match the API schema.的相关文章

Sass Loader报错:ValidationError: Invalid options object. Sass Loader has been initialised using an options object that does not match the API schema.

在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

[Android]通过js方法回调部分native报错 Web Console: Uncaught TypeError: Object [object Object] has no method &#39;xxx&#39;

在android4.2以前,注入步骤如下: webview.getSetting().setJavaScriptEnable(true); class JsObject { public String toString() { return "injectedObject"; } } webView.addJavascriptInterface(new JsObject(), "injectedObject"); Android4.2及以后,注入步骤如下: webv

python安装locustio报错error: invalid command &#39;bdist_wheel&#39;的解决方法

locust--scalable user load testing tool writen in Python(是用python写的.规模化.可扩展的测试性能的工具) 安装locustio需要的环境条件是:Python2.6+,但是不支持Python3. 今天在cmd里运行pip install locustio,报错提示:error: invalid command 'bdist_wheel'. 原因:pip和setuptools的版本较低. 解决方案:升级pip和setuptools. 一

全局变量报错:UnboundLocalError: local variable &#39;l&#39; referenced before assignment

总结: 内部函数,不修改全局变量可以访问全局变量 内部函数,修改同名全局变量,则python会认为它是一个局部变量 在内部函数修改同名全局变量之前调用变量名称(如print sum),则引发Unbound-LocalError 在程序中设置的sum属于全局变量,而在函数中没有sum的定义,根据python访问局部变量和全局变量的规则:当搜索一个变量的时候,python先从局部作用域开始搜索,如果在局部作用域没有找到那个变量,那样python就在全局变量中找这个变量,如果找不到抛出异常(NAMEE

全局变量报错:UnboundLocalError: local variable &#39;xxxxx&#39; referenced before assignment

daibuchong 参考:http://blog.csdn.net/my2010sam/article/details/17735159 http://blog.csdn.net/onlyanyz/article/details/45009697 http://blog.csdn.net/magictong/article/details/4464024 全局变量报错:UnboundLocalError: local variable 'xxxxx' referenced before ass

虚拟化--002 VCAC vcac配置sso一直报错

002 VCAC  vcac配置sso一直报错 1.选择用ia的sso失效,一直提示端口不能连接,用ip地址直接连,可以连接,但是还是会报错Error communicating to the remote server https://x.x.x.x..... 2.最后用的是vc的sso来连接,结果成功了,用的也是ip地址.

C#中当程序的访问权限不足时,Directory.Exists和File.Exists方法不会抛出异常报错

有些时候,我们开发的C#应用程序的执行账号,可能没有对一些文件夹和文件的访问权限,当我们使用Directory.Exists和File.Exists方法去判断这些文件夹和文件是否存在的时候,Directory.Exists和File.Exists方法并不会抛出异常报错,这两个方法会返回false,表示查找的文件夹和文件不存在.尽管文件夹和文件实际上是存在的,只是C#程序的执行账号没有权限访问而已,但是Directory.Exists和File.Exists方法还是会返回false,并不会抛出异常

VUE - 使用axios数据请求时数据绑定时 报错 TypeError: Cannot set property &#39;xxxx&#39; of undefined 的解决办法

created() { var that=this axios.get('http://jsonplaceholder.typicode.com/todos') .then(function (res) { // handle success // console.log(res); that.todos = res.data }) .catch(function (error) { // handle error console.log(error); }) .finally(function

配置MySQL主从复制报错Last_IO_Error: Fatal error: The slave I/O thread stops because master and slave have equal MySQL server ids; these ids must be different for replication to work

配置MySQL主从复制报错 Last_IO_Error: Fatal error: The slave I/O thread stops because master and slave have equal MySQL server ids; these ids must be different for replication to work (or the --replicate-same-server-id option must be used on slave but this do