Component cannot be used as a JSX component

今天在使用 React + Ts,使用 react-icons 这个库的时候,遇到了这个问题:

原因用一句话概括就是 Ts 的版本太低了!

我的 package.json:

json 复制代码
{
  "name": "frontend",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/dom": "^10.4.0",
    "@testing-library/jest-dom": "^6.6.3",
    "@testing-library/react": "^16.3.0",
    "@testing-library/user-event": "^13.5.0",
    "@types/jest": "^27.5.2",
    "@types/node": "^16.18.126",
    "react": "^18.3.1",
    "react-dom": "^18.3.1",
    "react-icons": "^5.5.0",
    "react-router-dom": "^6.30.1",
    "react-scripts": "5.0.1",
    "typescript": "^4.9.5",
    "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.3.23",
    "@types/react-dom": "^18.3.7",
    "@types/react-router-dom": "^5.3.3"
  }
}

我把版本改为 "typescript": "^5.8.3" 就可以了。

相关推荐
Bug生产工厂16 小时前
手把手教你把三方支付接口打包成 TypeScript SDK
typescript
OLong2 天前
第二章 - 抽象语法树(AST)概述
前端·typescript
Enheng9_92 天前
vue3项目开发细节记录
前端·vue.js·typescript
小宁爱Python2 天前
TypeScript 泛型详解:从基础到实战应用
前端·javascript·typescript
归于尽2 天前
从JS到TS:我们放弃了自由,却赢得了整个世界
前端·typescript
今晚一定早睡2 天前
new操作符
前端·javascript·typescript
pe7er3 天前
深入理解 TypeScript 的模板字面量类型 - 从 ms 库的类型定义说起
前端·typescript
小浣熊喜欢揍臭臭3 天前
react+antd+表格拖拽排序以及上移、下移、移到顶部、移到底部
前端·前端框架·react
小浣熊喜欢揍臭臭3 天前
react+antd 可拖拽模态框组件
前端·javascript·react