Can't use typescript with css modules
See original GitHub issueHi, 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?

Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:11 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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'
).This will work for parcel v2: https://www.npmjs.com/package/parcel-transformer-ts-css-modules