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

Viewed 43326

EDIT: Just discovered that not one single module installed through npm install --save can be resolved. The issue seems to be therefore with all modules even though they are located inside node_modules folder.

I have been debugging this error for the last 2 hours. Note that the application has been created with create-react-app tool.

This is how I am importing the module:

import AppBar from "@material-ui/core/AppBar";
import Button from "@material-ui/core/Button";
import Icon from "@material-ui/core/Icon";
import IconButton from "@material-ui/core/IconButton";
import Tabs from "@material-ui/core/Tabs";
import Tab from "@material-ui/core/Tab";

This is the package.json snippet:

...
"dependencies": {
    "@material-ui/core": "^1.5.1",
    "@material-ui/icons": "^1.1.1",
...
6 Answers

Try - yarn add @material-ui/core

This resolved the broken dependencies between materialui and react. Worked for me in my case, it was @material-ui/core/chippedInput that was missing.

I tried to use material-ui inside a docker container via docker-compose, when I got the same error. I had to reinitialize docker-compose via docker-compose down before running docker-compose up --build. Afterwards the import worked as expected.

What I noticed was, just by npm install it is not installing @material-ui/core package, we need to install it separately by npm install @material-ui/core. This method is the same for @material-ui/icons

In my case I was following a tutorial and ended up with an import as

import AppBar from 'material-ui/AppBar';

Instead of using the following which is in documentation here.

import AppBar from '@material-ui/core/AppBar';
// or
import { AppBar } from '@material-ui/core';
Related