MUI 错误:无法读取未定义的属性(读取“抽屉”)

cen*_*nak 5 javascript reactjs material-ui

我正在项目 MUI v5.0.2 上使用。一周前我的项目运行正常(没有错误),但是今天突然出现错误(代码没有任何变化)

错误: TypeError: Cannot read properties of undefined (reading 'drawer')

代码:

const useStyles = makeStyles((theme) => ({
  ...
  appBar: {
    zIndex: theme.zIndex.drawer + 1, //this line showed at error message
    transition: theme.transitions.create(['width', 'margin'], {
      easing: theme.transitions.easing.sharp,
      duration: theme.transitions.duration.leavingScreen,
    }),
  },
  ...
}));
Run Code Online (Sandbox Code Playgroud)

Visual Studio Code 还说: Property 'zIndex' does not exist on type 'DefaultTheme'

我尝试了这个解决方案,但没有帮助

也许有人知道如何解决它?

UPD:我尝试回滚到以前的提交,但是那里发生了同样的错误,尽管以前没有发生过这种情况

主题对象:

const theme = createTheme({
  palette: {
    primary: {
      light: '#757ce8',
      main: '#3f50b5',
      dark: '#002884',
      contrastText: '#fff',
    },
    secondary: {
      light: '#ff7961',
      main: '#f44336',
      dark: '#ba000d',
      contrastText: '#000',
    },
  },
});
Run Code Online (Sandbox Code Playgroud)

小智 12

我有一个类似的错误花了undefined (reading 'contrastText') 我一段时间才弄清楚,但这个错误来自我使用的芯片组件,问题是我使用而danger不是error在其中一个<Chip />组件中使用,这弄乱了整个网站。

更糟糕的是它没有告诉我这个错误来自哪里


cen*_*nak 0

这很奇怪,但解决方案是重新安装所有 MUI 软件包