13

i have a react application and trying to deploy it to Heroku and when runnung git push heroku master

Module not found: Error: Can't resolve '@material-ui/core/styles'

I searched for similar issues and installed the latest versions of npm, node and metarial-ui also i tried npm install @material-ui/core ..didn't work.

here is the full error-log file

-----> Build succeeded! =====> Downloading Buildpack: https://github.com/mars/create-react-app-inner-buildpack.git =====> Detected Framework: React.js (create-react-app) Writing static.json to support create-react-app Enabling runtime environment variables amusement-parks-europe@0.1.0 build /tmp/build_a49639db14111a3c4e29b2f3e9e25c49 react-scripts build Creating an optimized production build... Failed to compile. Module not found: Error: Can't resolve '@material-ui/core/styles' in '/tmp/build_a49639db14111a3c4e29b2f3e9e25c49/src' npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! amusement-parks-europe@0.1.0 build: react-scripts build npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the amusement-parks-europe@0.1.0 build script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /app/.npm/_logs/2018-10-08T20_29_28_807Z-debug.log ! Push rejected, failed to compile React.js (create-react-app) multi app. ! Push failed

and the project can be found on github react app using google Api

thanks for any help, I tried many ideas and came to no solution .

maher abedah
  • 391
  • 1
  • 3
  • 7

6 Answers6

26

the problem was solved according to the answer from @samokasha , the solution was using npm install @material-ui/core --save

I used the same command before but I missed the --save

thanks for the help.

maher abedah
  • 391
  • 1
  • 3
  • 7
  • As of npm 5.0.0, installed modules are added as a dependency by default, so the --save option is no longer needed. [link](https://stackoverflow.com/questions/19578796/what-is-the-save-option-for-npm-install) – Reza Aug 15 '19 at 08:52
  • just run `npm install @material-ui/core@next` – Reza Aug 15 '19 at 08:54
  • It worked for me but Whats the difference between the above and `code npm i --save @material-ui/core` – Rwiti Jun 21 '20 at 11:45
5

If you are using MUI 5 You need to change this

v5
import { withStyles } from '@mui/material/styles';


V4
import { withStyles } from '@material-ui/core/styles';

indianwebdevil
  • 4,879
  • 7
  • 37
  • 51
2

Looks like your package.json file doesn't include material-ui. Try 'npm i -s @material-ui/core'

kasho
  • 508
  • 4
  • 10
  • 1
    Check your package.json file. There you have material-ui installed. You need to install the @material-ui package with the following commands: "npm install @material-ui/core --save". Don't forget the "@" – kasho Oct 15 '18 at 21:52
0

Check your react version and run:

npm install @material-ui/core --save 

or run:

npm install @material-ui/core@next
Dhia Djobbi
  • 1,176
  • 2
  • 15
  • 35
0

for me was >> ‍npm i @material-ui/core --force

Ramin eghbalian
  • 2,348
  • 1
  • 16
  • 36
  • 1
    While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. – nima Oct 30 '22 at 07:36
0

Below command solves my error:

npm i @material-ui/core --force 
Dhaifallah
  • 1,437
  • 1
  • 5
  • 19