How to solve cannot find module ‘react’ and its corresponding type declarations
npm install @types/react-leaflet
Similarly, for other libraries, use the below command structure:
npm install @types/your_library_name
Now this will help solve this error. Let’s look at the second solution now.
By Creating a decs.d.ts file
If you create a decs.d.ts file in the root folder of your project with module name declaration, this can lead to the fix of your error. In this case, I am declaring the react-leaflet module in the decs.d.ts file as:
declare module ‘react-leaflet’
Similarly, for other libraries, use the below module structure:
declare module ‘LibraryName’
The decs.d.ts file is used to fix the “cannot find module ‘react’ and its corresponding type declarations” error. Let us look at the 3rd solution to fix the error:
This is yet another method using which we can fix the mentioned error. By using @ts-ignore, we can fix the error. We can use this as follows:
// @ts-ignore import Map from 'react-leaflet'
That’s it for this tutorial.
How to Solve cannot read property of null
How to Solve SyntaxError: Unexpected end of input
How to Solve Uncaught ReferenceError: required is not defined
How to solve reference error: window is not defined
How to solve reference error: document is not defined