In the browser, I get the error
Failed to compile Module not found: Can't resolve '@material-ui/core/Container'
It's looking for the component inside of my components directory instead of node_modules. I can't change directories into node_modules ../../
because node_modules is outside of src
directory and Create React App won't let me.
I've use yarn to remove and $ yarn add @material-ui/core
. I've tried yarn run build which gives me the error
Cannot find module: '@material-ui/core/Container'. Make sure this package is installed. You can install this package by running: yarn add @material-ui/core/Container.
When I try to add it, I get the error
error Couldn't find package "@material-ui/core/Container" on the "npm" registry.
Here's the dependencies I have that are related:
"@material-ui/core": "^3.9.3",
"@material-ui/icons": "^3.0.2",
"react": "^16.8.6",
"react-dom": "^16.8.6",
I expect to see the contents of the page not take up the full width of the screen, but instead, I receive a fail to compile error.
To solve the error "Module not found: Error: Can't resolve '@mui/material'", make sure to install the package by opening your terminal in your project's root directory and running the command npm i @mui/material @emotion/react @emotion/styled and restart your development server.
instead of makeStyles you can just create object with styles ( style={your styles} ) inside functional component and then use sx property( sx={style} ) on MUI component inside that functional component.
To check version numbers, run npm list @mui/material in the environment where you build your application and also in your deployment environment. You can also ensure the same version in different environments by specifying a specific MUI version in the dependencies of your package.
To solve the error "Module not found: Error: Can't resolve '@mui/material'", make sure to install the package by opening your terminal in your project's root directory and running the command npm i @mui/material @emotion/react @emotion/styled and restart your development server.
To solve the error "Module not found: Error: Can't resolve 'react/jsx-runtime'", make sure to update the react package by opening your terminal in your project's root directory and running the command npm install react@latest react-dom@latest and restart your dev server.
Make sure to restart your IDE and dev server if the error persists. VSCode often glitches and a reboot solves things sometimes. If you're still getting the "Module not found: Error: Can't resolve '@mui/material'" error, open your package.json file and make sure it contains the @mui/material package in the dependencies object.
Container is not part of the material-ui version specified in your package.json. You might have to remove the old stable version (if that's even an option for you). React and react-dom >= 16.8.0 are all that are needed as peer dependencies, so the experimental upgrade of material-ui should be all you need to use Container.
Container
is not part of the material-ui
version specified in your package.json
.
To upgrade, run the following:
$ yarn add @material-ui/core@next
You might have to remove the old stable version (if that's even an option for you).
React and react-dom >= 16.8.0 are all that are needed as peer dependencies, so the experimental upgrade of material-ui
should be all you need to use Container
.
I had a similar issue and I resolved it by calling:
for npm:
npm install @material-ui/core
for yarn:
$ yarn add @material-ui/core@next
If you follow a npx create-react-app new-app
with cd new-app
and yarn add @material-ui/core
it wile compile with yarn start
. You might try just starting over.
However, to help your troubleshooting, this error typically happens when you try to use a Material-UI component and forget to import it. Have you tried commenting out all the code and seeing if it compiles?
This error might also indicate that there are no node_modules for what is being imported. So, npm install
might solve the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With