MUI v5 crashes with Cannot read properties of undefined (reading 'create')
TypeError: Cannot read properties of undefined (reading 'create')Short answer
In MUI v5 the old makeStyles and withStyles from @mui/styles no longer get a default theme. Without a ThemeProvider at the root the theme is missing, so code that reads a theme value and calls .create on it fails. Add a ThemeProvider from @mui/material/styles, or move the styles to sx or styled.
Fix it fast
1Find out which cause you have
Look at the stack trace for your own file, then check whether that file or a parent uses makeStyles, withStyles or a theme value. The trace points at the style function that reads the theme.
grep -rn "@mui/styles\|makeStyles\|withStyles" src2Match what you see, then jump to its fix
- 1
The crash happens in a component that uses makeStyles or withStylesmakeStyles or withStyles runs with no ThemeProvider at the rootFix - 2
A ThemeProvider exists but the import line says @mui/styles, and Material UI components inside it still crashThemeProvider is imported from @mui/styles, not from @mui/material/stylesFix - 3
Many files import from @mui/styles and new components keep hitting theme errorsThe legacy JSS styling is still in use and should be migratedFix
- 1
What does the error look like?
TypeError: Cannot read properties of undefined (reading 'create')
Cause 1 of 3
makeStyles or withStyles runs with no ThemeProvider at the root
1Check
The MUI v5 migration guide states that makeStyles is no longer exported by @mui/material/styles, and tells you to add a ThemeProvider at the root because the defaultTheme is no longer available.
grep -rn "ThemeProvider" src2Fix
Create a theme and wrap the whole app in ThemeProvider from @mui/material/styles.
import { createTheme, ThemeProvider } from "@mui/material/styles";
const theme = createTheme();
root.render(
<ThemeProvider theme={theme}>
<App />
</ThemeProvider>
);3Verify
Reload. The component renders and the TypeError is gone.
npm run devConfirmed by mui.com
Cause 2 of 3
ThemeProvider is imported from @mui/styles, not from @mui/material/styles
1Check
The migration guide says to replace the use of ThemeProvider from @mui/styles with the one from @mui/material/styles, which makes the theme available to both the @mui/styles utilities and Material UI components.
grep -rn "ThemeProvider" src | grep "@mui/styles"2Fix
Change the import. makeStyles itself can stay for now if you import it from @mui/styles/makeStyles.
// before
import { ThemeProvider } from "@mui/styles";
// after
import { ThemeProvider } from "@mui/material/styles";3Verify
Run the app and open the page that failed.
npm run devConfirmed by mui.com
Cause 3 of 3
The legacy JSS styling is still in use and should be migrated
1Check
The JSS migration guide allows JSS overrides for a while after the upgrade, and recommends moving to sx or styled. It also says @emotion/styled must stay installed, as it is a peer dependency of @mui/material.
npm ls @emotion/react @emotion/styled @mui/styles2Fix
Move each makeStyles block to the sx prop or styled(), then remove @mui/styles when nothing imports it.
// after: styles move into the sx prop
<Chip sx={{ py: 1, px: 1.5, boxShadow: 1 }} label="New" />
# then, when no file imports @mui/styles
npm uninstall @mui/styles3Verify
Search the source; no file imports @mui/styles.
grep -rn "@mui/styles" srcConfirmed by mui.com
How do I stop it coming back?
- Wrap the app in one ThemeProvider from @mui/material/styles, even when you use the default theme.
- Write new styles with sx or styled, and migrate old makeStyles code file by file.
- Keep @emotion/react and @emotion/styled in package.json.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
Module not found: Can't resolve an @mui/icons-material icon import
Module not found: Can't resolve '@mui/icons-material/FileDownload'
The bundler cannot find a file at that import path.
3 causes, each with a fixWeb apps
Module not found for antd/dist/antd.less after upgrading to Ant Design 5
Module not found: Error: Can't resolve 'antd/dist/antd.less'
Ant Design 5 dropped Less and the bundled CSS file for CSS-in-JS, so antd/dist/antd.less no longer exists.
3 causes, each with a fixWeb apps
Astro Code component fails inside a React component
Astro components cannot be rendered directly via function call
Astro components such as Code only exist on the server and render static HTML.
2 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
How to catch and handle a 422 from Axios in a Redux thunk
action.error.message is 'Rejected' and action.payload is undefined
A 422 means the server read the request but cannot process its content, so repeating it unchanged fails again.
4 causes, each with a fixWeb apps
axios gets 429 Too Many Requests from a React app
429 (Too Many Requests)
A 429 comes from the server or an API gateway, not from axios: your client sent too many requests in a window.
4 causes, each with a fix