reactjs 这是我第一次使用mui,我不能正常导出导入{ DehazeIcon} from“@mui/icons-material”;错误(

rjzwgtxy  于 2023-05-17  发布在  React
关注(0)|答案(2)|浏览(133)

这是我第一次使用mui,我不能正常导出import { DehazeIcon } from "@mui/icons-material";给出错误。我的package.json

{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@emotion/react": "^11.10.0",
    "@emotion/styled": "^11.10.0",
    "@mui/icons-material": "^5.8.4",
    "@mui/lab": "^5.0.0-alpha.93",
    "@mui/material": "^5.9.3",
    "@mui/styled-engine-sc": "^5.9.3",
    "@testing-library/jest-dom": "^5.16.4",
    "@testing-library/react": "^13.3.0",
    "@testing-library/user-event": "^13.5.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-router-dom": "^6.3.0",
    "react-scripts": "5.0.1",
    "styled-components": "^5.3.5",
    "web-vitals": "^2.1.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "autoprefixer": "^10.4.8",
    "postcss": "^8.4.14",
    "tailwindcss": "^3.1.7"
  }
}

我的Header.js

import React from "react";
import { Link } from "react-router-dom";
import { DehazeIcon} from "@mui/icons-material";

//.....

 <div></div>
      <DehazeIcon/>
    </div>
  );
};

export default Header;

和错误:

我不明白错误是什么,4 mui不适合我,我也不想对17版本做出React。

c3frrgcw

c3frrgcw1#

您使用了错误的名称,MUI图标没有Icon后缀。您可以找到图标here的完整列表
相反,像这样导入:

import { Dehaze } from @mui/icons-material

或者你可以通过导入来改变它引用的名称,如下所示:

import { Dehaze as DehazeIcon } from @mui/icons-material

你也可以从默认的导出导入单个模块,就像恩菲尔德li在注解中添加的那样。请参阅此处的使用指南

r1zhe5dt

r1zhe5dt2#

试着像下面这样导入。

import DehazeIcon from '@mui/icons-material/Dehaze';

相关问题