Two ways to solve: Cannot find SVG module error when compiling Typescript in React application

Anna Coding
Anna Coding
Published in
2 min readMar 19, 2020

If you import SVG file in React Typescript file, for example, the following codes snippet:

🤔But, when you compile ExampleSVG.tsx file, you will see the following error:

src/components/Example/Example.tsx:4:18 — error TS2307: Cannot find module ‘../../assets/logo.svg’.

4 import Logo from ‘../../assets/logo.svg’;

Solution with custom.d.ts

Solution with require()

See solution in below link

More articles

--

--

Anna Coding
Anna Coding

Free web, mobile, DevOps, cloud tutorials, issues & solutions. www.annacoding.com