如何解决 “Component cannot be used as a JSX component“

原因是react版本与@types/react版本不一致导致的,
在tsconfig.json中加入以下代码,将依赖指向项目里的node_modules

"paths": {
   "react": [ "./node_modules/@types/react" ]
 }

改完后代码大概是长这样的

{
  "compilerOptions": {
  	...
    "paths": {
      "@/*": [
        "src/*"
      ],
      "@pages/*": [
        "src/pages/*"
      ],
      "react": [ "./node_modules/@types/react" ]
    }
    ...
}

你可能感兴趣的:(前端,javascript,react.js)