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.

Support CSS modules: Property '$style' does not exist on type

See original GitHub issue
  • I have searched through existing issues

Feature Request

It would be amazing if Vetur would support CSS modules using following syntax:

<template>
  <div :class="[$style.button]">
   Hello
  </div>
</template>

<style module>
.button {
  color: green;
}
</style>

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
iqingtingcommented, Apr 12, 2021

Add a new file in your project. You can get basic support.

// shims-css-module-vue.d.ts
import Vue from 'vue'

declare module 'vue/types/vue' {
  interface Vue {
    $style: Record<string, string>
  }
}

Unfortunately, this doesn’t work anymore with vue3 since the component type is the return type of the defineComponent function and you can’t augment a type with a new property like you can with an interface. Any ideas?

this worked to me

import { ComponentCustomProperties } from 'vue'

declare module '@vue/runtime-core' {
  interface ComponentCustomProperties {
    $style: {
      [key: string]: string
    }
  }
}
2reactions
yoyo930021commented, Oct 28, 2020

Add a new file in your project. You can get basic support.

// shims-css-module-vue.d.ts
import Vue from 'vue'

declare module 'vue/types/vue' {
  interface Vue {
    $style: Record<string, string>
  }
}

Read more comments on GitHub >

github_iconTop Results From Across the Web

Property 'styleName' does not exist on type 'HTMLProps ...
Use @types/react-css-modules. npm install --save-dev @types/react-css-modules. Or, yarn add @types/react-css-modules --dev.
Read more >
Property 'style' does not exist on type 'Element' in TS
The error "Property 'style' does not exist on type 'Element'" occurs when we try to access the style property on an element that...
Read more >
How to use CSS Modules with TypeScript and webpack
It's processed by webpack as usual but you won't have type check and autocomplete for CSS class names. The better way. To use...
Read more >
typescript-plugin-css-modules
This plugin provides type information to IDEs and any other tools that work with TypeScript language service plugins. At this time, TypeScript ...
Read more >
style-loader
Don't do that. component.js import styles from "./styles.lazy.css"; styles ...
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