Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material-UI Accordion (formerly ExpansionTable) component won't import

I am building an app using Material-UI, so far so good. I am trying to build a component using an Accordion component, but i am getting an error when trying to import it:

Module not found: Can't resolve '@material-ui/core/Accordion' in [path]

I have tried to import it both through a default and named imports, but the result is the same.

the component:

import React from 'react';
//  import {
//     Accordion,
//     AccordionSummary,
//     AccordionDetails
//  } from '@material-ui/core';
import Accordion from '@material-ui/core/Accordion';
import AccordionSummary from '@material-ui/core/AccordionSummary';
import AccordionDetails from '@material-ui/core/AccordionDetails';
import ExpandMoreIcon from '@material-ui/icons/ExpandMore';


const JobCard = () => {

    return(
        <Accordion expanded={true}>
            <AccordionSummary
                expandIcon={<ExpandMoreIcon />}
            >
                test
            </AccordionSummary>
            <AccordionDetails>
                test
            </AccordionDetails>
        </Accordion>
    );
}

export default JobCard;

All my other components are working fine with imported Material-UI components.

Am i missing something here that i am doing wrong? Did anyone encounter such an issue?

like image 776
Ybz Avatar asked Jul 01 '20 16:07

Ybz


People also ask

How do I import material-UI components in react?

We must install the Material-UI to access its different functionalities or components. Open your terminal, and ensure that you are inside your application's master folder. Type npm install @material-ui/core in the terminal and click enter. Run the command below to use Material-UI icons in our project.

What is material-UI accordion?

An accordion is a lightweight container that may either be used standalone, or be connected to a larger surface, such as a card. Feedback. WAI-ARIA. Bundle size. Material Design.


4 Answers

ExpansionPanel has been renamed to Accordion . With your error, it looks like you are using material-ui-core version 4.10.2 (or below).

Use material-ui-core version 4.11.0 or higher.

Working demo of your code in codesandbox

like image 120
gdh Avatar answered Oct 09 '22 05:10

gdh


Install Material UI Core

npm i @material-ui/core

So , it will be @material-ui/[email protected]

Then, its working. Have fun!!

like image 28
siva surya Avatar answered Oct 09 '22 04:10

siva surya


I had basically the same issue. Error was:

"Can't resolve '@material-ui/icons/ExpandMore'"

After installing the following:

"@material-ui/core": "^4.11.0",
"@material-ui/icons": "^4.9.1",
"avatar": "^0.1.0",
"clsx": "^1.1.1",
"jquery": "^3.5.1",
"material-ui": "^0.20.2",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"react-ga": "^2.7.0",
"react-scripts": "1.0.17"

I ran npm update and ALL WAS GOOD :)

like image 2
Jon Christie Avatar answered Oct 09 '22 04:10

Jon Christie


The name of Accordion has been changed to ExpansionPanel lately, So import like this:

import Accordion from '@material-ui/core/ExpansionPanel';
import AccordionSummary from '@material-ui/core/ExpansionPanelSummary';
import AccordionDetails from '@material-ui/core/ExpansionPanelDetails';
import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
like image 1
Amir Fo Avatar answered Oct 09 '22 04:10

Amir Fo