简体   繁体   English

MUI:从material v4升级到v5后,提供的`styles`参数无效

[英]MUI: The `styles` argument provided is invalid after upgrading from material v4 to v5

I recently upgraded from Material V4 to V5 and I'm now getting the following error:我最近从 Material V4 升级到 V5,现在出现以下错误:

MUI: The `styles` argument provided is invalid.
You are providing a function without a theme in the context.
One of the parent elements needs to use a ThemeProvider.

Within my App.js file, I have the following setup:在我的App.js文件中,我有以下设置:

import { createTheme, ThemeProvider, StyledEngineProvider, adaptV4Theme } from '@mui/material/styles';
import makeStyles from '@mui/styles/makeStyles';
import { CssBaseline, Hidden } from '@mui/material';


let theme = createTheme(adaptV4Theme({
  palette: {
    primary: {
      light: '#63ccff',
      main: '#009be5',
      dark: '#006db3'
    }
  },
  typography: {
    h5: {
      fontWeight: 500,
      fontSize: 26,
      letterSpacing: 0.5
    }
  },
  shape: {
    borderRadius: 8
  },
  props: {
    MuiTab: {
      disableRipple: true
    }
  },
  mixins: {
    toolbar: {
      minHeight: 48
    }
  }
}));

theme = {
  ...theme,
  overrides: {
    MuiDrawer: {
      paper: {
        backgroundColor: '#18202c'
      }
    }
  }
};

and then have the following return within my App.js:然后在我的 App.js 中返回以下内容:

  const classes = useStyles();

  return (
    <NotifyProvider>
        <Routes>
          <Route path="/login" element={<Login />}></Route>
          <Route path="/logout" element={<Logout />}></Route>
        </Routes>
          <StyledEngineProvider injectFirst>
            <ThemeProvider theme={theme}>
              <div className={classes.root}>
                <CssBaseline />
                <nav className={classes.drawer}>
                </nav>
                <div className={classes.app}>
                  <Header
                    onDrawerToggle={handleDrawerToggle}
                  />
                  <main className={classes.main}>
                    <Routes>
                      <Route path="/" />
                    </Routes>
                  </main>
                </div>
              </div>
            </ThemeProvider>
          </StyledEngineProvider>
    </NotifyProvider>
  );

I'm not sure what the issue is and what I am missing but I also noticed that adaptV4Theme is depracated.我不确定问题是什么以及我缺少什么,但我也注意到adaptV4Theme已被弃用。

Any help would be great as the app is not starting at all.任何帮助都会很棒,因为该应用程序根本没有启动。

i am having the same issue.我有同样的问题。 there is a thread here: https://github.com/mui/material-ui/issues/30092 with some troubleshooting suggestions.这里有一个线程: https ://github.com/mui/material-ui/issues/30092 以及一些故障排除建议。 none of them worked for me but some others in the thread seem to have resolved the issue by deleting yarn.lock and rerunning yarn install , see thread for more details.他们都没有为我工作,但线程中的其他一些人似乎已经通过删除yarn.lock并重新运行yarn install解决了这个问题,有关更多详细信息,请参阅线程。 if you do solve it please post here and let me know what fixed it, have been working at this for several days with no luck.如果您确实解决了它,请在此处发布并让我知道修复了什么,已经为此工作了几天,但没有运气。

ETA -- I was able to solve this in my app by wrapping the components I was testing in a <ThemeProvider/> , as suggested here: https://github.com/mui/material-ui/issues/15528#issuecomment-487952731 (I was only getting the error message when testing) ETA - 我能够通过将我正在测试的组件包装在<ThemeProvider/>中来在我的应用程序中解决这个问题,如下所示: https ://github.com/mui/material-ui/issues/15528#issuecomment- 487952731 (我只是在测试时收到错误消息)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 mui v4 迁移到 v5 | TypeError:无法读取未定义的属性(读取“keyboardDate”) - Migrating from mui v4 to v5 | TypeError: Cannot read properties of undefined (reading 'keyboardDate') 将 webpack 从 v4 更新到 v5 后无法解析项目依赖项中的 polyfill 包 - Can't resolve polyfill packages in project dependencies after updating webpack from v4 to v5 道具类型失败:提供给“字段”的道具“组件”无效。 安装 mui v4 后 - Failed prop type: Invalid prop `component` supplied to `Field`. after installing mui v4 将 material-ui v3 升级到 v4 导致 redux 表单字段组件错误“无效的道具组件” - Upgrading material-ui v3 to v4 causes redux form Field component error 'invalid prop component' 带有情感的 MUI v5 主题/mui - MUI v5 theming with emotion/mui React Routing 不工作,从 v5 升级到 v6 - React Routing not working, upgrading from v5 to v6 从反应路由器 v5 升级到 v6 - Upgrading from react router v5 to v6 将 D3 从 v4 升级到 v6 后,轴移动到图形中心 - Axis moving to center of graph after upgrading D3 from v4 to v6 在 MUI v5 ReactJS 上从 widthWidth 更改为 useWidth - Change from widthWidth to useWidth on MUI v5 ReactJS Mui v5 styleOverrides 不适用于主题 - Mui v5 styleOverrides not working with themes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM