Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 615
Jessica Avatar asked May 21 '19 03:05

Jessica


People also ask

Could not resolve mui material?

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.

How do I import makeStyles into material UI?

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.

How do I check my MUI version?

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.

How to solve the error “module not found”?

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.

How to solve the error 'module not found' in ReactJS?

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.

How do I resolve '@Mui/material' error in VSCode?

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.

Is it possible to use React container with material-UI?

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.


3 Answers

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.

like image 133
Ezra Avatar answered Sep 22 '22 04:09

Ezra


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
like image 28
Mohammad Avatar answered Sep 19 '22 04:09

Mohammad


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.

like image 31
Chase Owens Avatar answered Sep 21 '22 04:09

Chase Owens