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.

Can't use typescript with css modules

See original GitHub issue

Hi, I’m bootstrapping a simple project with react and typescript and I can’t seem to import css modules correctly.

This works: import './styles.css'

This doesn’t import * as classes from './styles.css'

Am I missing something?

screen shot 2018-01-22 at 13 27 55

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
fathybcommented, Jan 23, 2018

Use declare module '*.css' on an ambient .d.ts file on your project to let TypeScript know you are using CSS modules.

Adding { const css: any; export default css } will restrict you from importing named classes (eg. import {myClass} from './index.css').

6reactions
dmitrijs-balcerscommented, Aug 29, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to import CSS modules with Typescript, React and ...
Generate (or auto-generate) .d.ts files for CSS? And use classic Typescript import statement? With ./styles.css.d.ts : import * as styles from './styles.css'.
Read more >
How to use CSS Modules with TypeScript and webpack
Using CSS Modules with TypeScript is not as obvious as with JavaScript. The reason is that TypeScript has special treatment for import s...
Read more >
Increasing the Value of CSS Modules with Typescript
Increasing the Value of CSS Modules with Typescript · 1. Create a New Project · 2. Rename CSS Files · 3. Import CSS...
Read more >
typescript-plugin-css-modules - npm
CSS modules support for TypeScript. Latest version: 4.1.1, last published: 23 days ago. Start using typescript-plugin-css-modules in your ...
Read more >
CSS modules and TypeScript doesn't work very well together
Go to declaration/refactoring work fine if css is imported using default import syntax: import styles from "./styles.css" , don't work when importing entire ......
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