S
SolidJS5mo ago
zimo

"Cannot find module" for image files

Whenever I do something like
import favicon from "./assets/favicon.ico";
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)
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;
}
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"]
}
{
"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?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server