Cannot find module '@vitejs/plugin-react' or its corresponding type

I have created the project using npm create vite@latest and I choose ts-react, when I ran the script the npm run dev worked, no warning however, I am getting an Cannot find module '@vitejs/plugin-react' or its corresponding type in vite.config.ts in vs code.

Screenshot of error

Upvotes: 30

Views: 56209

Answers (8)

JaNei
JaNei

Reputation: 1

All solutions didn't work for me! When I was navigating to the folder:

\node_modules@tanstack\router-plugin\

in my project it showed, that there is no vite.ts file which is very weired.

Copying the vite.ts file from

\node_modules@tanstack\router-plugin\src\

into the parent directory, fixed it for me. Not sure what went wrong during my installation process.

Edit: In the end I copied all files from \src\ since vite.ts has many dependencies

Upvotes: 0

Pavel Lobarev
Pavel Lobarev

Reputation: 311

If you are using SWC!


Use "@vitejs/plugin-react-swc", instead of "@vitejs/plugin-react".

Upvotes: 20

Jayanta Madhav
Jayanta Madhav

Reputation: 121

Cannot find module '@vitejs/plugin-react' or its corresponding type

The question itself is hinting what the issue is. You need to install '@vitejs/plugin-react'. For some reason it doesn't get included when you create a vite project.

If you're using yarn

yarn add @vitejs/plugin-react

if you're using npm

npm i -S @vitejs/plugin-react 

Upvotes: 9

Gautam Vanama
Gautam Vanama

Reputation: 115

Adding "types": ["vite"] in my tsconfig.json file worked for me.

Upvotes: 0

Mara
Mara

Reputation: 403

In my case the problem was that I forgot to run yarn in terminal ( or npm install if you use npm) just after initial creation of project ( npm create vite@latest or yarn create vite ). Because vite needs to install all dependencies in package.json and create node_modules folder

Upvotes: 7

MNN
MNN

Reputation: 302

In my case it was that I forgot to install types:

$ npm i -D @types/node

Upvotes: 3

Kevin Hernández
Kevin Hernández

Reputation: 844

Restart your TS Server following these steps:

  1. Open Command Palette: Command + Shift + P.
  2. Search TypeScript: Restart TS server.
  3. Press Enter.

Upvotes: 20

bagus prasetyo
bagus prasetyo

Reputation: 638

Try to restart your VSCode editor

Upvotes: 49

Related Questions