类型“JSX. IntrinsicElement”上不存在属性“div”,当我用vite创建react typescript项目时

gpfsuwkq  于 2023-05-08  发布在  TypeScript
关注(0)|答案(1)|浏览(1561)

当我在VScode中使用vite创建react typescript项目时,App.tsx中总是出现以下错误。

Property 'div' does not exist on type 'JSX.IntrinsicElements'.
Property 'a' does not exist on type 'JSX.IntrinsicElements'.Property 'img' does not exist on type 'JSX.IntrinsicElements'.

我用vite npm create vite@latest npm install npm i -D @types/react-dom创建项目
它可以在浏览器中运行,但在vscode中总是有错误。我尝试了一些解决方案,但它不工作。
tsconfig.json中也有一些错误

Option '--resolveJsonModule' cannot be specified without 'node' module resolution strategy.
Option '--resolveJsonModule' cannot be specified without 'node' module resolution strategy.
Option '--resolveJsonModule' cannot be specified without 'node' module resolution strategy.

我将把App.js和tsconfig.json放在附件中。
Typescript complains Property does not exist on type 'JSX.IntrinsicElements' when using React.createClass?
typescript suddenly yelling at me about all p tags - "property 'p' does not exist on type 'JSX.IntrinsicElements'

g9icjywg

g9icjywg1#

**TL;DR:**确保您的Visual Studio代码是最新的(版本1.77+)

你好,我发现你的问题,同时寻找解决这个问题的办法。我想我会回来给你留个回复因为我找到了一个适合我的方法。
This answer到一个类似的问题为我工作的最后。我所要做的就是将我的VSCode更新到1.78版本,因为我使用的是1.71版本。您可以参考原始答案来解释为什么会导致问题,但是更新VSCode应该可以解决您的问题😊
希望这个能帮你解决!

相关问题