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.

SCSS - Importing SCSS variables globally breaks exported TS type to `{}`.

See original GitHub issue

Thanks for the awesome TS plugin! 💪

Describe the bug There’s certain cases when using SASS where you need the value of a variable and need to wrap it in #{} in order to get the variable output and not the variable name.

When adding #{} to a *.module.scss, the file’s classNames etc are no longer exported and only shows {} in the TS file.

To Reproduce

Add the following to any *.module.scss file, and try and import it to a TS file.

container.module.scss

@use "variables" as *; // Which includes $breakpoint

.container {
  @media (min-width: #{$breakpoint}) {
    color: red;
  }
}

Expected behavior Using the #{} functionality shouldn’t remove the classNames.

Desktop (please complete the following information):

  • OS: iOS
  • Browser: Chrome
  • Version: 96.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:16
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
kirill-martynovcommented, Jul 1, 2022

@kirill-martynov No and I’m still frustrated by it.

I really want this plugin to work.

@mrmckeb 🙏

me too, we have a lot of media query global variables on a project, but when we are using them, it’s always showing empty type {}

With custom media global variables @media #{$new-tablet-only} { 176881718-b12741af-9858-4183-8d29-7dfc965564cc

Without custom media global variables Screenshot 2022-07-01 at 14 03 32

@mrmckeb please help us to fix this issue

4reactions
mthinescommented, Jan 13, 2022

I think it’s related to https://github.com/mrmckeb/typescript-plugin-css-modules/issues/146.

Trying to add the variable directly to the scss fixed the error. I have a SCSS configuration in my NextJS app which includes all my resources, and I think that needs to be set in the same way for the plugin.

const nextConfig = {
  sassOptions: {
      prependData: '@use "libs/theme/src/lib/resources.scss" as *;',
    },
  ...
}

I will try and update the tsconfig plugin settings, and see if I can get it to work 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to infer types from modular scss exports? - Stack Overflow
Basically the approach is: Create a modular scss file containing your scss variables, or import them from the original files using @use ....
Read more >
Use Sass Variables In Typescript & Javascript | Matt Ferderer
I was using "require" module to import the scss variables like static variables: any = require('../scss/_variables.scss'); It was perfectly ...
Read more >
Sass: @import
@import makes all variables, mixins, and functions globally accessible. This makes it very difficult for people (or tools) to tell where anything is...
Read more >
Content Types - ESBuild
#Import from JavaScript ... Note that esbuild doesn't yet support CSS modules, so the set of JavaScript export names from a CSS file...
Read more >
Standard Styling with Global CSS Files - Gatsby
Importing CSS files into components. It is also possible to break up your CSS styles into separate files so that team members can...
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