Next.js: TS Error using CSS/SCSS Modules in TypeScript

Created on 10 Dec 2019  ·  3Comments  ·  Source: vercel/next.js

Bug report

Describe the bug

Try to use CSS Modules in TypeScript the same way I would use them in JavaScript, l see an error: ”TS2307: Cannot find module './styles.css'”.

To Reproduce

I think webpack css-loader should be updated.

Expected behavior

I should not see such an error

Screenshots

Screen Shot 2019-12-10 at 01 02 02

System information

  • OS: [macOS]
  • Version of Next.js: [9.1.5]

Most helpful comment

you can add this to the next-env.d.ts file.

declare module '*.scss' {
  const content: string;
  export default content;
}

All 3 comments

how to get red out of this error

you can add this to the next-env.d.ts file.

declare module '*.scss' {
  const content: string;
  export default content;
}

you can add this to the next-env.d.ts file.

declare module '*.scss' {
  const content: string;
  export default content;
}
declare module '*.scss' {
    const classes: { [key: string]: string};
    export default classes;
}

Works better since you don't get any errors in the code about undeclared props.

Found it here: https://spin.atomicobject.com/2020/06/22/css-module-typescript/

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wagerfield picture wagerfield  ·  3Comments

sospedra picture sospedra  ·  3Comments

jesselee34 picture jesselee34  ·  3Comments

formula349 picture formula349  ·  3Comments

swrdfish picture swrdfish  ·  3Comments