SolidJSS
SolidJSโ€ข2y ago
zimo

"Cannot find module" for image files

Whenever I do something like
import favicon from "./assets/favicon.ico";
I get a TS error of
Cannot find module './assets/favicon.ico' or its corresponding type declarations.ts(2307)
. Same goes for .module.css files, but .css imports correctly.

I tried adding a declarations.d.ts file:
declare module '*.module.css' {
    const classes: { [key: string]: string };
    export default classes;
}

declare module '*.(png|ico|svg|jpg|jpeg|gif|bmp|tiff)' {
    const value: string;
    export default value;
  }


Which I import in tsconfig, restart the TS server but the error persists:
{
  "compilerOptions": {
    ...
  },
  "include": ["src", "src/declarations.d.ts"]
}


It all compiles fine and the files are found, it's just an annoying TS error.

Any idea why this happens and how to fix this?
Was this page helpful?