I get a typescript error in my vite project when I try to import an SVG with a suffix (?component). How can I configure typescript to ignore these suffixes?
TS2307: Cannot find module './desktop-mark.svg?component' or its corresponding type declarations.
import DesktopLogoMark from './desktop-mark.svg?component';
You need to add module declaration: https://www.typescriptlang.org/docs/handbook/modules.html#wildcard-module-declarations
E.g. in declarations.d.ts:
declare module "*?raw"
{
const content: string;
export default content;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With