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.
8 Answers
Try to restart your VSCode editor
-
Yes, I reopened the browser next morning, and the problems were fixed, Commented Mar 5, 2022 at 16:30
-
Restart your TS Server following these steps:
- Open Command Palette:
Command
+Shift
+P
. - Search
TypeScript: Restart TS server
. - Press
Enter
.
-
1Yes, that seems to be the issue. Please update the top answer to include all cases that might solve the issue– LuciferCommented Apr 19, 2023 at 10:42
If you are using SWC!
Use "@vitejs/plugin-react-swc"
, instead of "@vitejs/plugin-react"
.
-
1
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
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
-
Yep, this was my problem. I just assumed it would be added when I installed Vite. Don't forget to add
vite.config.js
as well!– RaydotCommented Mar 23 at 21:58 -
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