Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Cannot find name 'div'.ts(2304)" when creating a new React application?

I have created a new React application with the command: "npx create-react-app poi-search --template typescript". When opening the files, ESLint asked me for permission. After that there were only errors. Picture here: enter image description here

I have the latest version of VSCode.

Here my tsconfig:

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

}

This is the automatically generated configuration.

like image 355
avydesign Avatar asked Sep 17 '25 02:09

avydesign


2 Answers

This seems to be a VSCode's bug. Here is a few ways you could use to fix it.

  1. Just restart VSCode.
  2. If you don't want to close VSCode. You could press ⇧⌘P / Ctrl+Shift+P and type reload. Then select Developer: Reload Window to reload VSCode.

All worked for me.

like image 126
Even Wonder Avatar answered Sep 19 '25 16:09

Even Wonder


I got the same issue with NextJS app in VSCode, my solution is:

  1. Uninstall an old React extension in VSCode.
  2. Restart VSCode.

That worked for me!

like image 27
Nguyễn Đình Hiếu Avatar answered Sep 19 '25 16:09

Nguyễn Đình Hiếu