Search code examples
cssreactjswordpresscss-modulesreact-css-modules

How to use CSS modules in a React based Wordpress plugin?


I have this line in one of my tsx file:

import styles from "../../styles/buyTicket.module.css";

got this error:

ERROR in /Applications/MAMP/htdocs/wp-content/plugins/tikex/tikexModule/components/BuyTicket/PricingOptionInvoiceItemsFormFieldsCheckboxes.tsx
./tikexModule/components/BuyTicket/PricingOptionInvoiceItemsFormFieldsCheckboxes.tsx 7:19-54
[tsl] ERROR in /Applications/MAMP/htdocs/wp-content/plugins/tikex/tikexModule/components/BuyTicket/PricingOptionInvoiceItemsFormFieldsCheckboxes.tsx(7,20)
      TS2307: Cannot find module '../../styles/buyTicket.module.css' or its corresponding type declarations.

If I remove styles then I got this error no more, but then it will work not as a CSS module, and naming collosion will happen. What would you suggest?


Solution

  • As far as i can understand, you may have a look here:
    Can't import CSS/SCSS modules. TypeScript says "Cannot Find Module"

    and here:
    React, Typescript - Cannot find module ... or its corresponding type declarations