npm refuses to install @material-ui/core 4 next to a newer React
npm error code ERESOLVEShort answer
Material UI v4 declares peer React versions up to 17, so npm 7+ stops when your app uses a newer React. The lasting fix is upgrading to @mui/material (v5 and later), the only line that fully supports React 18. Use the official codemod for the renames instead of editing every import by hand.
Fix it fast
1Find out which cause you have
List what pulls in the old package, so you know whether your code or a library asks for it.
npm ls @material-ui/core react2Match what you see, then jump to its fix
- 1
npm ls shows @material-ui/core as a direct dependency of your appYour own code still imports @material-ui/coreFix - 2
Imports of makeStyles or withStyles from the old packageYou still use makeStyles or withStylesFix - 3
ERESOLVE names @material-ui/icons or @material-ui/labIcons or lab packages are still on the old namesFix
- 1
What does the error look like?
npm error code ERESOLVECould not resolve dependency: peer react@"^16.8.0 || ^17.0.0" from @material-ui/core@4.12.4
Cause 1 of 3
Your own code still imports @material-ui/core
1Check
The migration guide says v5 requires React 17 or later and is the only version that fully supports React 18.
grep -rln "@material-ui/" src/ | head2Fix
Install the v5 packages, run the official codemod on your source folder, then remove the old packages.
npm install @mui/material @emotion/react @emotion/styled
npx @mui/codemod@latest v5.0.0/preset-safe src
npm uninstall @material-ui/core3Verify
A clean install passes and the app builds.
npm install
npm run buildConfirmed by mui.com
Cause 2 of 3
You still use makeStyles or withStyles
1Check
The guide describes @mui/styles as the deprecated JSS-based package that lets you keep makeStyles and withStyles while migrating. It requires a ThemeProvider at the app root.
grep -rn "makeStyles\|withStyles" src/ | head2Fix
Install @mui/styles as a stop-gap, wrap the app in ThemeProvider, and move components to the newer styling API afterwards.
npm install @mui/styles3Verify
The app renders and the styled components keep their look.
npm run devConfirmed by mui.com
Cause 3 of 3
Icons or lab packages are still on the old names
1Check
Each v4 package has a renamed successor in the guide, for example icons and lab.
npm ls @material-ui/icons @material-ui/lab2Fix
Install the renamed packages and let the codemod rewrite the imports.
npm install @mui/icons-material @mui/lab
npm uninstall @material-ui/icons @material-ui/lab3Verify
No @material-ui package is left in the tree.
npm ls | grep material-uiConfirmed by mui.com
How do I stop it coming back?
- Commit package-lock.json so a CI install resolves the same tree.
- Check the peer range of a UI library before you upgrade React.
- Do the MUI upgrade on its own branch, with the app building before and after.
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
Back end
npm install refuses with ERESOLVE and a peer dependency conflict
npm error ERESOLVE unable to resolve dependency tree
ERESOLVE means two packages in your tree ask for incompatible versions of a shared peer dependency, and npm 7 or newer refuses to guess.
3 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
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 fix