cabinbody
cabinbody

Reputation: 1

How to fix “Cannot find name ‘div’.ts(2304)” in a React project built with Vite and TypeScript?

I’m encountering a strange issue in my React project built with Vite and TypeScript. The error message Cannot find name 'div'.ts(2304) appears when using HTML elements like div in JSX. However, the error disappears when I add a space anywhere in the code. Once I make another change to the code, the error comes back again.

Can anyone guide me on how to resolve this issue? enter image description here enter image description here

I am using React and TypeScript in a Vite project. I’m using .tsx extension for my files (not .ts). I’ve installed the required type declarations for React (@types/react, @types/react-dom). I’ve checked my tsconfig.json, and the jsx option is set to "react-jsx" (since I am using React 18). I’ve also tried importing React at the top of my files, but the error still occurs.

Upvotes: -1

Views: 24

Answers (0)

Related Questions