close

[Solved] Cannot find module ‘react’ or its corresponding type declarations

Hello Guys, How are you all? Hope You all Are Fine. Today I am facing following error with my newly created reactjs Project Cannot find module ‘react’ or its corresponding type declarations in ReactJs. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Cannot find module ‘react’ or its corresponding type declarations Error Occurs ?

I am facing following error with my newly created reactjs Project.

Cannot find module 'react' or its corresponding type declarations

How To Solve Cannot find module ‘react’ or its corresponding type declarations Error ?

  1. How To Solve Cannot find module ‘react’ or its corresponding type declarations Error ?

    To Solve Cannot find module ‘react’ or its corresponding type declarations Error You Need to install types for Libraries. For Example we need to instlall react-leaflet Then We Have to use following command with types: npm install @types/react-leaflet For Other Libraries You Have to use following command structure: npm install @types/your_lib_name Now, Your error should be solved.

  2. Cannot find module ‘react’ or its corresponding type declarations

    To Solve Cannot find module ‘react’ or its corresponding type declarations Error Just need to Create a decs.d.ts file at the root of our Project Directory and declare your module name. In My case I want to declare react-leaflet module then I will write following line in my decs.d.ts file: declare module ‘react-leaflet’ You Can Use following structure to declare your module: declare module “libName” Now, Your problem must be solved.

Solution 1: Install types for libraries

You Need to install types for Libraries. For Example we need to instlall react-leaflet Then We Have to use following command with types.

npm install @types/react-leaflet

For Other Libraries You Have to use following command structure.

npm install @types/your_lib_name

Now, Your error should be solved.

Solution 2: Create a decs.d.ts file

Just need to Create a decs.d.ts file at the root of our Project Directory and declare your module name. In My case I want to declare react-leaflet module then I will write following line in my decs.d.ts file.

declare module 'react-leaflet'

You Can Use following structure to declare your module.

declare module "libName"

Now, Your problem must be solved.

Solution 3: Using @ts-ignore

suppress the error using @ts-ignore Just like this.

// @ts-ignore  
import Map from 'react-leaflet'

Summary

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?

Also, Read

Leave a Comment