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

Reactstrap Button无法作为JSX组件使用的技术问题求助

解决Reactstrap Button的JSX组件类型错误

问题根源

该错误源于项目中@types/react、@types/react-dom的类型定义版本与reactstrap依赖的版本不兼容,导致ReactNode等核心类型的定义出现冲突。

解决步骤

1. 统一React类型包版本

执行以下命令卸载现有类型包,重新安装与reactstrap兼容的版本(以适配React 18的类型版本为例):

npm uninstall @types/react @types/react-dom
npm install @types/react@^18.2.0 @types/react-dom@^18.2.0 --save-dev

2. 清理依赖并重启项目

清除旧依赖缓存后重新安装,再重启开发服务:

rm -rf node_modules package-lock.json
npm install
npm start

3. 升级reactstrap(可选)

如果你的reactstrap版本过低(比如低于v9),无法适配React 18,执行升级命令:

npm install reactstrap@latest bootstrap@latest

4. 临时类型声明修复(备用方案)

若上述方法无效,在项目src目录下创建declarations.d.ts文件,添加如下类型声明:

declare module 'reactstrap' {
  import { ComponentType, ReactNode } from 'react';
  export const Button: ComponentType<{
    children?: ReactNode;
    [prop: string]: any;
  }>;
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 11:30:05