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

87,830

Solution 1

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.

Solution 2

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

Solution 3

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.

Share:
87,830
Jessica
Author by

Jessica

Updated on July 09, 2022

Comments

  • Jessica
    Jessica almost 2 years

    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.