Whenever I try to import material ui icons and core an error appears saying module not found? How to solve it?

Viewed 473

[This is the error shown whenever I try to use @material-ui/core and icons

`import React from "react";
import "./Sidebar.CSS";
import SearchIcon from "@material-ui/icons/Search";

const Sidebar = () => {
  return (
    <>
      <div className="sidebar">
        <div className="sidebar__header">
          <SearchIcon />
        </div>
        <div className="sidebar__search"></div>
        <div className="sidebar__chats"></div>
      </div>
    </>
  );
};

export default Sidebar;

`]1

3 Answers

are you sure you have run

// with npm
npm install @material-ui/icons

// with yarn
yarn add @material-ui/icons

Because if you haven't then react won't know where to look for the icons

This could be happening because of the following reasons.

  1. Material UI is not installed properly. Delete the material UI package from node modules folder.Add material UI package under dependencies (not under devDependencies) and delete package-lock.json and try non install again

  2. SearchIcon will be a named export Use import { SearchIcon } from "@material-ui/icons/Search";

Related