[英]Module not found: Can't resolve '@mui/icons-material/FileDownload'
I have installed both @material-ui/core
and @material-ui/icons
.我已经安装了
@material-ui/core
和@material-ui/icons
。
I am trying to import "FileDownloadIcon" from Material icons.我正在尝试从 Material 图标导入“FileDownloadIcon” 。
Installing "@material-ui/core" :安装“@material-ui/core” :
npm i @material-ui/core
Installing "@material-ui/icons" :安装“@material-ui/icons” :
npm i @material-ui/icons
This is the way I am trying to import "FileDownloadIcon" :这是我尝试导入“FileDownloadIcon”的方式:
import FileDownloadIcon from '@mui/icons-material/FileDownload';
<div className="download-file">
<Button
variant="contained"
color="primary"
onClick={() => getResume()}
>
<FileDownloadIcon />
Download Resume
</Button>
</div>
But it's occurring error like this "Module not found: Can't resolve '@mui/icons-material/FileDownload' in 'E:\frontend\src\component\Details'"但它正在发生这样的错误“找不到模块:无法在‘E:\frontend\src\component\Details’中解析‘@mui/icons-material/FileDownload’”
Can anyone tell me where is the problem?谁能告诉我问题出在哪里?
FileDownload icon is added in v5, it does not exist in v4. FileDownload图标是 v5 中添加的,v4 中不存在。 You can search for v4 icons here .
您可以在此处搜索 v4 图标。 To use the v5 icon in the older version of MUI, just go and copy the source code here :
要在旧版 MUI 中使用 v5 图标,只需在此处复制源代码:
function FileDownload(props) {
return (
<SvgIcon {...props}>
<path d="M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z" />
</SvgIcon>
);
}
EDIT: If you are using MUI v5 already, it means you're missing the icon package.编辑:如果您已经在使用 MUI v5,则意味着您缺少图标包。 Follow the installation guide here to install:
按照此处的安装指南进行安装:
npm install @mui/icons-material
use the migration from v4 to v5 following this link https://mui.com/guides/migration-v4/按照此链接https://mui.com/guides/migration-v4/使用从 v4 到 v5 的迁移
you can do:你可以做:
// with npm npm install @mui/icons-material // 使用 npm npm 安装 @mui/icons-material
or this:或这个:
You seem to be using v5 of Material-UI.您似乎正在使用 Material-UI 的 v5。 Use the following:
使用以下内容:
import { FileDownload } from "@mui/icons-material";
Notice the name of the icon, omitting Icon
.注意图标的名称,省略
Icon
。 Then use it with the button:然后通过按钮使用它:
<div className="download-file">
<Button
variant="contained"
color="primary"
onClick={() => getResume()}
startIcon={<FileDownload />}>
Download Resume
</Button>
</div>
npm install @mui/icons-material (OR) npm install -g @material-ui/icons npm install @mui/icons-material (OR) npm install -g @material-ui/icons
only if you'll use @mui/icons-material
仅当您使用
@mui/icons-material
时
npm install @mui/icons-material --force
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.