Netlify部署时@material-ui/core与@types/react依赖冲突求助
Fixing Material UI Dependency Conflict in Netlify Deployment
The core issue here is your project has a mix of Material UI v4 (@material-ui/* packages) and MUI v5 (@mui/* packages). These two versions have conflicting peer dependency requirements for React types:
- Material UI v4 only supports
@types/react^16.8.6 || ^17.0.0 - MUI v5 supports
@types/react^17.0.0 || ^18.0.0
Here are two actionable solutions:
Option 1: Migrate Fully to MUI v5 (Recommended)
MUI v4 is no longer maintained, so upgrading to v5 is the long-term fix:
- Uninstall all v4 packages:
npm uninstall @material-ui/core @material-ui/icons @material-ui/lab @material-ui/styles - Install v5 equivalents and required peer dependencies:
npm install @mui/material @mui/icons-material @mui/lab @emotion/react @emotion/styled - Update all imports in your code from
@material-ui/[package]to@mui/[package] - Clean and reinstall dependencies:
rm -rf node_modules package-lock.json npm install - Redeploy your site on Netlify.
Option 2: Fix Material UI v4 Setup (Short-Term)
If you can’t migrate to v5 right now, eliminate all v5 packages and align React versions:
- Uninstall all v5 packages:
npm uninstall @mui/material @mui/icons-material @mui/lab @mui/base - Install React 17 and compatible types:
npm install react@^17.0.2 react-dom@^17.0.2 --save npm install @types/react@^17.0.75 @types/react-dom@^17.0.24 --save-dev - Clean and reinstall dependencies:
rm -rf node_modules package-lock.json npm install - If Netlify still throws errors, update your build command in Netlify’s Site Settings > Build & Deploy to:
npm run build --legacy-peer-deps
Content of this question is sourced from Stack Exchange, asked by Omri Bitan.
相关产品推荐
相关产品推荐

