i'm trying to import a png in my typescript react project like so:
import logo from 'assets/Logo.svg';
I'm getting this TS error though:
Cannot find module 'assets/Logo.svg' or its corresponding type declarations.ts(2307)
Any idea why this is? I have attached my tsconfig.json
file below in case I have configured something incorrectly:
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"baseUrl": "src"
},
"include": ["src"]
}
CodePudding user response:
there is a react-app-env.d.ts
file in your project
just add the code bellow in that file.
declare module "*.png";
declare module "*.svg";
declare module "*.jpeg";
declare module "*.jpg";