0

im new to react and next js so sorry for my idiotic question, im trying to install material ui in a new next js app (i used "npx create-next-app@latest"), and im using the Material ui docs and the ts section (https://mui.com/guides/typescript/#main-content)

i got the following error in cli / terminal:

npm install @mui/material @emotion/react @emotion/styled
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR!   peer react@">=16.8.0" from @emotion/react@11.8.2      
npm ERR!   node_modules/@emotion/react
npm ERR!     @emotion/react@"*" from the root project
npm ERR!     peerOptional @emotion/react@"^11.5.0" from @mui/material@5.5.3
npm ERR!     node_modules/@mui/material
npm ERR!       @mui/material@"*" from the root project
npm ERR!     1 more (@emotion/styled)
npm ERR!   1 more (@emotion/styled)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^17.0.0" from @mui/material@5.5.3
npm ERR! node_modules/@mui/material
npm ERR!   @mui/material@"*" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!

i have tried to use the material ui component and got a compiler error, even though i have tried in a nextjs (without ts and with) and with the flags: --force, or --legacy-peer-deps

please help! a lot of thanks in advance! i just need to start my project!

install material ui in next-js with and without typescript

SnakeDoc
  • 13
  • 3

2 Answers2

0

If I had this problem I would have deleted package.json and installed it again and after that I try to install Material. Did you try this?

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 02 '22 at 15:01
0

Run this command. Just worked for me.

npm install @mui/material @emotion/react @emotion/styled --force

I also deleted my node_modules and did another install to be sure. and it found 0 vulnerabilities.