Import CSS Modules with TypeScript and webpack

InstructorArtem Sapegin

Share this video with your friends

Send Tweet

If you try to use CSS Modules in TypeScript the same way you would use them in JavaScript, with webpack’s css-loader, you’ll see an error: ”TS2307: Cannot find module './styles.css'”. typings-for-css-modules-loader is a drop-in replacement for css-loader that works with TypeScript and generates typings for CSS on the fly.

You’ll need to install dependencies first:

npm install --save-dev css-loader typings-for-css-modules-loader