Reputation: 441
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.
Upvotes: 30
Views: 56209
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
Reputation: 311
If you are using SWC!
Use "@vitejs/plugin-react-swc"
, instead of "@vitejs/plugin-react"
.
Upvotes: 20
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
Reputation: 115
Adding "types": ["vite"] in my tsconfig.json file worked for me.
Upvotes: 0
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
Reputation: 302
In my case it was that I forgot to install types:
$ npm i -D @types/node
Upvotes: 3
Reputation: 844
Restart your TS Server following these steps:
Command
+ Shift
+ P
.TypeScript: Restart TS server
.Enter
.Upvotes: 20