Sass Loader Error: Invalid options object that does not match the API schema

后端 未结 7 496
别跟我提以往
别跟我提以往 2020-12-16 09:40

I\'m using VueJS with the framework VuetifyJS (v2.0.19). I\'m getting this error after running npm run serve:

Sass Loader has been initialise

相关标签:
7条回答
  • 2020-12-16 10:01

    indentedSyntax is part of the sassOptions:

    sassOptions: {  indentedSyntax: true  }
    

    For example:

    {
        loader: 'sass-loader',
        options: {
            sassOptions: {
                indentedSyntax: true
            }
        }
    }
    

    So - change your Webpack config to reflect that.

    0 讨论(0)
  • 2020-12-16 10:11

    In my case I had to downgrage sass-loader, after which I got the real error emmitted on the terminal when I run ng serve, which whould be vue-cli-service in your case I think it's a problem with v8 of sass-loader, will dig further

    In the meantime, this might help: In the package.json, edit the sass-loader to read "sass-loader": "7.0.1",

    0 讨论(0)
  • 2020-12-16 10:12

    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 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 :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 it will fix the invalid options errors.

      css: {
        loaderOptions: {
          sass: {
            additionalData: `@import "@/assets/styles/variables/index.scss";`
          }
        }
      }
    
    0 讨论(0)
  • 2020-12-16 10:15

    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 sass-loader@7.1.0
    
    0 讨论(0)
  • 2020-12-16 10:19

    I had the same issue when upgrading to sass-loader 10. I resolved it by replacing prependData with additionalData as per below:

    {
      test: /\.scss$/,
      loader: 'sass-loader',
      options: {
        additionalData: `@import 'src/scss/helpers/variables';`
      }
    }
    
    0 讨论(0)
  • 2020-12-16 10:24

    If you are using vue-cli 4 and in order to avoid this error you need to change the config of sass-loader in vue.config.js like the example below, after that the error will be fixed.

    const path = require('path');
    
    module.exports = {
      chainWebpack(config) {
        config
          .entry('app')
          .clear()
          .add('./src/core/main.js')
          .end();
        config.resolve.alias
          .set('~', path.join(__dirname, './src'))
          .set('@', path.join(__dirname, './src/core'))
          .set('#', path.join(__dirname, './src/modules'))
      },
      css: {
        loaderOptions: {
          sass: {
            sassOptions: {
              includePaths: [
                path.resolve(__dirname, 'src/core/')
              ],
              indentedSyntax: true,
            },
            prependData: '@import "~@/assets/sass/main.scss"',
          },
        },
      },
      assetsDir: '@/assets/',
    }
    

    Don't forget to specify your own configuration. Please checkout the configuration on the sass-loader repo.

    If you use vue cli 3, it works with sass-loader v7 not with v8 if you use vue cli 3 and sass-loader v7 the previous configuration still works.

    Good luck and regards.

    0 讨论(0)
提交回复
热议问题