You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VSCode中TypeScript模板报错:无法找到元素名的排查求助

问题:VSCode中首次打开的.tsx文件出现Cannot find name 'div'.ts(2304)错误

问题详情

  • 错误仅出现在VSCode中首次打开的.tsx文件,无论先打开哪个文件,IntelliSense运行后都会显示该错误,其余文件均正常。
  • 重装VSCode和Node后,执行npx create-react-app my-app-test --template typescript创建新项目,2周前正常运行的旧项目如今也出现此前未有的该错误。
  • 有时问题会自行消失,但新建文件时问题仍会出现;重启VSCode无法解决问题,之前正常的文件也会再次报错。
  • 代码编译无任何错误,但VSCode内会提示Cannot find name 'div'.ts(2304)错误。

已尝试的解决手段

  • 重新安装VSCode、Node、npm
  • 切换VSCode中的TypeScript版本
  • 在电脑不同目录创建项目
  • 执行npm cache clean
  • 禁用所有扩展运行VSCode

版本信息

  • 全局tsc版本:tsc -v → Version 5.4.4
  • Node版本:node -v → v20.12.1
  • VSCode版本:1.88
  • VSCode内置tsc版本:5.4.3
  • 操作系统:Windows 10

tsconfig.json配置

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "include": [
    "src"
  ]
}

package.json配置

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@emotion/react": "^11.11.4",
    "@mui/material": "^5.15.14",
    "@reduxjs/toolkit": "^2.2.3",
    "@testing-library/jest-dom": "^5.17.0",
    "@testing-library/react": "^13.4.0",
    "@testing-library/user-event": "^13.5.0",
    "@types/jest": "^27.5.2",
    "@types/node": "^16.18.94",
    "axios": "^1.6.8",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-redux": "^9.1.0",
    "react-router-dom": "^6.22.3",
    "react-scripts": "5.0.1",
    "redux-persist": "^6.0.0",
    "web-vitals": "^2.1.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "@types/react": "^18.2.74",
    "@types/react-dom": "^18.2.24",
    "typescript": "^4.9.5"
  }
}

内容的提问来源于stack exchange,提问作者jsilber

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 12:28:14