react 项目构建时构建失败提示XXXcannot be used as a JSX component

react 项目构建时构建失败提示XXXcannot be used as a JSX component

admin
2023-06-06 / 0 评论 / 562 阅读 / 正在检测是否收录...

react 项目构建时构建失败,报错信息如下

[2023-06-06 11:12:51]TS2786: 'StatusTip' cannot be used as a JSX component.
[2023-06-06 11:12:51]  Its type 'FunctionComponent> & { LoadingTip: ForwardRefExoticComponent>; EmptyTip: ForwardRefExoticComponent<...>; FoundTip: ForwardRefExoticComponent<...>; ErrorTip: ForwardRefExoticComponent<...>; }' is not a valid JSX element type.
[2023-06-06 11:12:51]    29 |       <>
[2023-06-06 11:12:51]    30 |         <CommonHeader />
[2023-06-06 11:12:51]  > 31 |         <StatusTip style={{ position: 'absolute', ...loadingStyle, top: '45%' }} status="loading" />
[2023-06-06 11:12:51]       |          ^^^^^^^^^
[2023-06-06 11:12:51]    32 |       </>
[2023-06-06 11:12:51]    33 |     );
[2023-06-06 11:12:51]    34 |   }
[2023-06-06 11:12:51]src/common/LazyLoading.tsx:36:13

错误信息其实很明确,因为项目原来是好好的,在流水线中构建,突然出现的问题,肯定是构建环境问题,报错内容大概是说函数的返回值类型不能用作react组件,所以判断是ts的类型校验和我们原有项目的react版本不兼容,
所以通过同步ts的版本和react的类型声明文件的版本解决

yarn add -D  @types/react@latest @types/react-dom@latest
1

评论 (0)

取消