Sometimes, we want to fix the "Cannot find module" error with importing images in TypeScript React.
In this article, we’ll look at how to fix the "Cannot find module" error with importing images in TypeScript React.
How to fix the "Cannot find module" error with importing images in TypeScript React?
To fix the "Cannot find module" error with importing images in TypeScript React, we should declare the .jpg
module in a TypeScript type definition file.
For instance, we write
declare module '*.jpg';
in index.d.ts
in the TypeScript project folder to let the TypeScript compiler know that .jpg
files can imported into our project directly.
Conclusion
To fix the "Cannot find module" error with importing images in TypeScript React, we should declare the .jpg
module in a TypeScript type definition file.