【发布时间】:2022-11-10 23:50:30
【问题描述】:
我在 Azure DevOps 中有一个构建管道,我正在尝试使用它构建一个前端 React Typescript 应用程序。此应用程序使用 Material ui,问题似乎出在该库的代码上。我之前已经构建了这个项目,但是由于某种原因,现在当我运行构建时,我收到了这个错误代码:
'Box' cannot be used as a JSX component.
Its element type 'ReactElement<any, any> | Component<BoxProps, any, any> | null' is not a valid JSX element.
Type 'Component<BoxProps, any, any>' is not assignable to type 'Element | ElementClass | null'.
Type 'Component<BoxProps, 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/vsts/work/1/s/node_modules/@types/react-router/node_modules/@types/react/index").ReactNode'.
Type '{}' is not assignable to type 'ReactNode'. TS2786
68 | <React.Fragment>
69 | <div>
> 70 | <Box component="nav" className={classes.Nav}>
| ^
71 | <AppBar position="relative" className={classes.appBarStyles}>
72 | <Toolbar className={classes.toolbarStyles}>
73 | <div className={classes.toggleSlider}>
这是导航栏的代码:
return (
<React.Fragment>
<div>
<Box component="nav" className={classes.Nav}>
<AppBar position="relative" className={classes.appBarStyles}>
<Toolbar className={classes.toolbarStyles}>
.....
</Toolbar>
</AppBar>
</Box>
</div>
</React.Fragment>
);
升级了materialui、react和react-dom的版本,以及typescript类型;我尝试用 div 封闭 Box 元素,并尝试使用 typescript 忽略标志,但似乎都没有解决问题。
我之前已经能够构建这个项目,所以我不太确定错误来自哪里。任何帮助表示赞赏,谢谢。
【问题讨论】:
标签: javascript reactjs typescript azure-devops material-ui