【问题标题】:Type 'React.ReactNode' is not assignable to type 'import(".../@types/react-transition-group/node_modules/@types/react/index").ReactNode'类型 \'React.ReactNode\' 不可分配给类型 \'import(\".../@types/react-transition-group/node_modules/@types/react/index\").ReactNode\'
【发布时间】:2022-08-02 20:02:36
【问题描述】:

我使用过 React 项目,与 Circle CI 集成,经过一些小的更改后,它开始使所有构建失败

Its instance type \'ReactApexChart\' is not a valid JSX element.
    The types returned by \'render()\' are incompatible between these types.
      Type \'React.ReactNode\' is not assignable to type \'import(\"/home/circleci/app.mxney-board-v2.test/node_modules/@types/react-transition-group/node_modules/@types/react/index\").ReactNode\'.

79       <Chart options={fillOptions} series={graphData} height={chartHeight} />
          ~~~~~

src/index.tsx:20:8 - error TS2786: \'App\' cannot be used as a JSX component.
  Its element type \'ReactElement<any, any> | Component<Omit<Subtract<unknown, WithTranslationProps>, keyof WithTranslation<N>> & WithTranslationProps, any, any> | null\' is not a valid JSX element.
    Type \'Component<Omit<Subtract<unknown, WithTranslationProps>, keyof WithTranslation<N>> & WithTranslationProps, any, any>\' is not assignable to type \'Element | ElementClass | null\'.
      Type \'Component<Omit<Subtract<unknown, WithTranslationProps>, keyof WithTranslation<N>> & WithTranslationProps, any, any>\' is not assignable to type \'ElementClass\'.
        The types returned by \'render()\' are incompatible between these types.
          Type \'React.ReactNode\' is not assignable to type \'import(\"/home/circleci/app.mxney-board-v2.test/node_modules/@types/react-transition-group/node_modules/@types/react/index\").ReactNode\'.

20       <App />
          ~~~

在本地,项目运行没有问题。

我试过了:

  • 更新@types 和库
  • 删除 react-apexchart 库
  • 移除 react-transition 库
  • 删除 yarn.lock 一个 node_modules 并重新安装 - 这会破坏一切,我在本地收到此错误
  • 我解决了这个问题 - 问题在于 HOC export const App = hot(withTranslation()(AppComponent)) 将其更改为 export const App = hot(withTranslation()(AppComponent as React.FC))

标签: reactjs typescript yarnpkg circleci


【解决方案1】:

您的 @types/react 是否与您安装的 react 版本匹配?

【讨论】:

  • 就我而言,是的
  • 在我的情况下发生了什么,我在另一台设备上克隆了存储库并尝试创建一个构建并且它在那里工作。问题出在我的设备上,只是它无法正常工作并给出相同的错误
猜你喜欢
  • 2019-07-08
  • 2022-11-18
  • 2022-11-11
  • 2019-02-02
  • 2019-01-24
  • 2017-09-25
  • 2019-06-28
  • 2020-07-22
  • 2018-12-08
相关资源
最近更新 更多