1

When trying to install material ui get a load of dependency resolution errors. Not quite sure what the cause is. I previously tried to install V4 and got an error, that I thought I would resolve by using V5 because this version of React isn't compatible with V4 but I have no idea about the rest of the conflicts.

npm i @mui/material @emotion/react @emotion/styled
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: @material-ui/core@4.12.4
npm ERR! Found: react@18.2.0
npm ERR! node_modules/react
npm ERR!   peer react@"^18.0.0" from @testing-library/react@13.3.0
npm ERR!   node_modules/@testing-library/react
npm ERR!     dev @testing-library/react@"^13.3.0" from the root project
npm ERR!   peer react@">=16" from phosphor-react@1.4.1
npm ERR!   node_modules/phosphor-react
npm ERR!     dev phosphor-react@"^1.4.1" from the root project
npm ERR!   18 more (react-dom, react-dropzone, react-media, react-popper, ...)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.8.0 || ^17.0.0" from @material-ui/core@4.12.4
npm ERR! node_modules/@material-ui/core
npm ERR!   @material-ui/core@"^4.12.4" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: react@17.0.2
npm ERR! node_modules/react
npm ERR!   peer react@"^16.8.0 || ^17.0.0" from @material-ui/core@4.12.4
npm ERR!   node_modules/@material-ui/core
npm ERR!     @material-ui/core@"^4.12.4" from the root project
npm ERR!
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.   

package.json:

 {
  "name": "wordscramble",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@material-ui/core": "^4.12.4",
    "@testing-library/jest-dom": "^5.16.4",
    "@testing-library/user-event": "^13.5.0",
    "bootstrap": "^5.2.0",
    "jquery": "^3.6.1",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-dropzone": "^14.2.2",
    "react-media": "^1.10.0",
    "react-router": "^6.3.0",
    "react-scripts": "5.0.1",
    "react-tinder-card": "^1.4.5",
    "reactstrap": "^9.1.2",
    "web-vitals": "^2.1.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "@testing-library/react": "^13.3.0",
    "fetch-mock": "^9.11.0",
    "msw": "^0.44.2",
    "phosphor-react": "^1.4.1",
    "react-redux": "^8.0.2",
    "react-router-dom": "^6.3.0",
    "react-test-renderer": "^18.2.0"
  }
}

Any help in identifying any potential conflicts would be greatly appreciated, thanks!

Jack Goodwin
  • 99
  • 1
  • 6

2 Answers2

0

1- uninstall @material-ui :

 npm uninstall @material-ui/core

2 - install Mui v5 :

npm install @mui/material @mui/styled-engine-sc styled-components
monim
  • 3,641
  • 2
  • 10
  • 25
0

Works with --legacy-peer-deps:

npm i @mui/material @emotion/react @emotion/styled --legacy-peer-deps

For more details see react v17 section on this answer https://stackoverflow.com/a/66620869/1515819

Stéphane Bruckert
  • 21,706
  • 14
  • 92
  • 130