英文:
Property 'div' does not exist on type 'JSX.IntrinsicElements'. when I create the react typescript project with vite
问题
在使用 Vite 在 VScode 中创建 React TypeScript 项目时,总是在 App.tsx 中出现以下错误。
```jsx
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 中也存在一些错误
选项 '--resolveJsonModule' 不能在没有 'node' 模块解析策略的情况下指定。
选项 '--resolveJsonModule' 不能在没有 'node' 模块解析策略的情况下指定。
选项 '--resolveJsonModule' 不能在没有 'node' 模块解析策略的情况下指定。
我会将 App.js 和 tsconfig.json 放在附件中。
<details>
<summary>英文:</summary>
when I createhe react typescript project with vite in VScode, there are always the fellowing errors in 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'.
I create the project with vite
`npm create vite@latest
npm install
npm i -D @types/react-dom
`
It can run in the browser, but there are always error in the vscode. I have tryed some solutions, but it doesn't work.
There are also some error in 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.
I will put the App.js and tsconfig.json in the attachement.
[Typescript complains Property does not exist on type 'JSX.IntrinsicElements' when using React.createClass?](https://stackoverflow.com/questions/37414304/typescript-complains-property-does-not-exist-on-type-jsx-intrinsicelements-whe)
[typescript suddenly yelling at me about all p tags - "property 'p' does not exist on type 'JSX.IntrinsicElements'](https://www.reddit.com/r/learnprogramming/comments/tva7wv/typescript_suddenly_yelling_at_me_about_all_p/)
</details>
# 答案1
**得分**: 5
**TL;DR:** 确保你的Visual Studio Code是最新的(版本1.77+)
嗨,我在寻找解决方案时发现了你的问题。想着我找到了一个对我有效的解决方法,所以过来给你留个回复。
[这个答案][1] 对我最终起作用。我所做的一切就是将我的VSCode更新到1.78版本,因为我使用的是1.71版本。你可以参考原始答案以了解为什么这会导致问题,但更新VSCode应该解决你的问题 😊
希望这对你有帮助!
[1]: https://stackoverflow.com/a/76089894/20219684
<details>
<summary>英文:</summary>
**TL;DR:** Make sure that your Visual Studio Code is up to date (Version 1.77+)
Hi, I found your question while looking for a solution for this myself. Figured I'd come back and leave you a reply since I found a fix that worked for me.
[This answer][1] to a similar question worked for me in the end. All I had to do was update my VSCode to version 1.78 as I was using version 1.71. You can refer to the original answer for an explanation of why this caused an issue, but updating your VSCode should fix your issue 😊
Hope this fixes it for you!
[1]: https://stackoverflow.com/a/76089894/20219684
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论