Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript errors when using a suffix (?raw, ?url etc

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';
like image 938
Carl Wirkus Avatar asked Apr 24 '26 06:04

Carl Wirkus


1 Answers

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;
}
like image 107
Алексей Мартинкевич Avatar answered Apr 26 '26 00:04

Алексей Мартинкевич