简体   繁体   中英

Cannot find module 'module.css' or its corresponding type declarations

Don't know why typescript suddenly not recogize my code, it show

Cannot find module './hookStyle/useMemostyle.module.css' or its corresponding type declarations

It happen when i move style to another folder

Here is typescript config

{
  "compilerOptions": {
    "lib": [
      "ESNext",
      "dom"
    ],
    "outDir": "lib",
    "removeComments": true,
    "target": "ES6",
    "baseUrl": "src",
    "esModuleInterop": true,
    "moduleResolution": "node",
    "sourceMap": true,
    "sourceRoot": "/",
    "alwaysStrict": true,
    "allowUnreachableCode": false,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "noImplicitReturns": true,
    "noUncheckedIndexedAccess": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "allowJs": true,
    "skipLibCheck": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "include": [
    "./**/*.ts"
  ],
  "exclude": [
    "node_modules/**/*"
  ]
}

It not effect the code, it still working but why typescript show that error? How can i fix it?

To import custom file types, you must use TypeScript's declare module syntax to let it know that it's ok to import. To do this, simply create a globals.d.ts (declaration file) wherever your other code's root directory is and then add in this code:

declare module '*.css';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM