question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug Report] Unable to utilize SASS variables - breaks build and testing processes

See original GitHub issue

Versions and Environment

Vuetify: 2.0.0 Vue: 2.6.10 Browsers: Chrome 75.0.3770.142 OS: Mac OS 10.14.5

Steps to reproduce

  • Clone the repo
  • npm i
  • start dev server
  • observe build process output

Expected Behavior

No errors

Actual Behavior

Errors relating to using sass variables on single-file components.

Reproduction Link

https://github.com/MatthewAry/vuetify-sass-variables

Other comments

Some background

I followed the directions https://vuetifyjs.com/en/customization/sass-variables and did some experiments. Attempts to try to use Single File components with styles with the instructions to override vuetify SASS variables fails. https://vuetifyjs.com/en/customization/sass-variables#single-file-components attempts to address this problem but it does not seem to work.

This code:

// vue.config.js

module.exports = {
  css: {
    loaderOptions: {
      sass: {
        data: `@import "~@/sass/main.scss"`,
      },
    },
  },
}

will break the build process.

So will this code:

// vue.config.js

module.exports = {
  css: {
    loaderOptions: {
      sass: {
        data: `@import "~@/sass/main.scss";`,
      },
    },
  },
  chainWebpack: config => {
    ["vue-modules", "vue", "normal-modules", "normal"].forEach((match) => {
      config.module.rule('sass').oneOf(match).use('sass-loader')
        .tap(opt => Object.assign(opt, { data: `@import '~@/sass/main.sass'` }))
    })
  }
}

Note that the Object.assign(opt, { data: `@import '~@/sass/main.sass'` }) and the data: `@import "~@/sass/main.scss";`, paths are different? Trying to make them match also does not fix the problem.

Related to: https://github.com/vuejs/vue-cli/issues/4116 Related to: #7795 Documentation Reference: https://vuetifyjs.com/en/customization/sass-variables

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
nekosaurcommented, Jul 25, 2019

So I think I got this working in your test repo in two different ways depending on if you want to use scss or sass in the SFC.

sass

Note the absence of a ; on the import statement

// vue.config.js
css: {
  loaderOptions: {
    sass: {
      data: '@import "~@/sass/main.scss"',
      implementation: require("sass"),
      fiber: require("fibers")
    }
  },
  sourceMap: true
}

You can then use sass style in SFC and use variables

<style lang="sass">
.test
  color: map-get($red, 'base')
</style>

scss

Note the config modification where we make sure there is a ; present when using scss

// vue.config.js
css: {
  loaderOptions: {
    sass: {
      data: '@import "~@/sass/main.scss"',
      implementation: require("sass"),
      fiber: require("fibers")
    }
  },
  sourceMap: true
},
chainWebpack: config => {
  ["vue-modules", "vue", "normal-modules", "normal"].forEach((match) => {
    config.module.rule('scss').oneOf(match).use('sass-loader')
        .tap(opt => Object.assign(opt, { data: `@import '~@/sass/main.scss';` }))
  });
}

You can then use scss in SFC

<style lang="scss">
.test {
  color: map-get($red, "base");
}
</style>
3reactions
MatthewArycommented, Jan 22, 2020

It seems that the documentation that was added in response to this issue has been removed since Vuetify 2.2. What is the recommended way to create global styles that may even override vuetify styles with this update?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring Test Coverage - Code Climate
The Code Climate test coverage reporter takes a supported test coverage report, transforms it into a generalized format, and submits it to Code...
Read more >
Sass Guidelines
An opinionated styleguide for writing sane, maintainable and scalable Sass.
Read more >
JavaScript "use strict" - W3Schools
The purpose of "use strict" is to indicate that the code should be executed in "strict mode". With strict mode, you can not,...
Read more >
node.js - SassError: Undefined variable. Failing dependencies
Bootstrap v5.2 introduced a new file called _maps.scss . You must add it to your main Sass file. Load your bootstrap modules in...
Read more >
How to Use Warnings and Errors in Sass Effectively - SitePoint
Sass tries to perform a map-get(..) on 42 and emits an error because it cannot be done. While the error message is correct,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found