13
votes

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.

2
It looks like Container is part of material-ui's "next" release, as I'm not able to find any references to it other than their documentation for the upcoming version. - Ezra

2 Answers

21
votes

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.

2
votes

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?