Module not found: Can't resolve '@material-ui/core' after an update or clone
Module not found: Can't resolve '@material-ui/core/Container'Short answer
Material UI v4 was published as @material-ui/core. Since v5 the packages are named @mui/material and @mui/icons-material. Code that still imports the old names fails once the old package is gone. Install the new packages and run the preset-safe codemod on your source folder.
Fix it fast
1Find out which cause you have
List every file that still imports the old scope.
grep -rln "@material-ui/" src2Match what you see, then jump to its fix
- 1
The failing import starts with @material-ui/The code still uses the v4 package namesFix - 2
Imports like @mui/material/styles/createTheme fail after an upgradeOld multi level import paths on a newer versionFix - 3
@mui/material resolves, but @mui/icons-material or @mui/lab errors appearRelated Material UI packages on mixed versionsFix
- 1
What does the error look like?
Module not found: Can't resolve '@material-ui/core/Container'Cannot find module '@material-ui/icons'
Cause 1 of 3
The code still uses the v4 package names
1Check
Material UI v5 renamed the packages: @material-ui/core is now @mui/material and @material-ui/icons is now @mui/icons-material.
grep -n "material-ui\|@mui" package.json2Fix
Install the new packages with the Emotion styling engine they use, then run the codemod once per folder. It also removes the old @material-ui packages.
npm install @mui/material @emotion/react @emotion/styled
npm install @mui/icons-material
npx @mui/codemod@latest v5.0.0/preset-safe src3Verify
Build the project and commit after the build is green.
npm run buildConfirmed by mui.com
Cause 2 of 3
Old multi level import paths on a newer version
1Check
Newer major versions no longer support multi level deep imports.
grep -rn "@mui/material/styles/" src2Fix
Import from the first level path.
// before
import createTheme from '@mui/material/styles/createTheme'
// after
import { createTheme } from '@mui/material/styles'3Verify
Rebuild the project.
npm run buildConfirmed by mui.com
Cause 3 of 3
Related Material UI packages on mixed versions
1Check
The sibling packages are versioned with the core package, so they should be moved together.
npm ls @mui/material @mui/icons-material @mui/lab2Fix
Update the sibling packages to the same major version as @mui/material, and keep @types/react matching your React major version.
npm install @mui/material@latest @mui/icons-material@latest3Verify
npm ls shows one version of each package.
npm ls @mui/material @mui/icons-materialConfirmed by mui.com
How do I stop it coming back?
- Pin the Material UI major version in package.json and review the migration guide before moving it.
- Run the codemod folder by folder and commit after each one.
- Copy snippets from the current docs, not from old tutorials.
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.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
Related fixes
Web 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
AxiosError Network Error with code ERR_NETWORK in a React app
Network Error
ERR_NETWORK means the request produced no readable response.
4 causes, each with a fixWeb apps
Axios get works with a URL string but ignores the object passed as the second argument
The server log shows a GET with no query string
axios.get takes a URL and an optional config object.
3 causes, each with a fixWeb apps
Can't resolve '../axios' in a React project
Module not found: Error: Can't resolve '../axios'
A path that starts with ./ or ../ is a file path, not the axios package.
3 causes, each with a fixWeb apps
Axios returns 401 from a React app but the login works elsewhere
Error: Request failed with status code 401
A 401 means the server received the request without valid credentials.
3 causes, each with a fixWeb apps
An axios call never finishes when the API server stops answering
code: 'ECONNABORTED'
Axios has no timeout unless you give it one: the default is 0, which means wait forever.
3 causes, each with a fix