简体   繁体   中英

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

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",
...

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.

The solution that worked for me is the following:

npm install  @material-ui/core

Check the link https://www.npmjs.com/package/@material-ui/core

I came across this question while trying to work with the material-ui table. Additional to installing the @material-ui/core via npm, make sure you install npm install @material-ui/icons , fromhttps://material-ui.com/getting-started/installation/#svg-icons

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.

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';

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM