简体   繁体   English

找不到模块:无法解析“@mui/icons-material/FileDownload”

[英]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:或这个:

  1. npm install @mui/material @mui/styles npm install @mui/material @mui/styles
  2. npm install @emotion/react @emotion/styled npm install @emotion/react @emotion/styled

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.

相关问题 如何解决找不到模块错误:找不到模块:无法解析“@mui/icons-material/Adb”? - How to solve module not found error : Module not found: Can't resolve '@mui/icons-material/Adb'? 未找到模块:错误:无法解析 &#39;D:\ 中的 &#39;@mui/icons-material/Menu&#39; - Module not found: Error: Can't resolve '@mui/icons-material/Menu' in 'D:\ 无法从@mui/icons-material 导入图标 - Unable to import icons from @mui/icons-material MUI:找不到模块“找不到模块:错误:无法解析&#39;时刻&#39;” - MUI : Module not found "Module not found: Error: Can't resolve 'moment' " 未找到 MUI 模块:无法解析“@emotion/react” - MUI Module not found: Can't resolve '@emotion/react' 找不到 ChakraUI React 导入模块:无法解析“@public/icons” - ChakraUI React import Module not found: Can't resolve '@public/icons' "未找到模块:无法解析“material-ui\/styles\/colors”" - Module not found: Can't resolve 'material-ui/styles/colors' 找不到模块:无法解析“@material-ui/core/Container” - Module not found: Can't resolve '@material-ui/core/Container' 未找到模块:无法解析“E:\frontend\node_modules\@mui\styled-engine”中的“@emotion/react” - Module not found: Can't resolve '@emotion/react' in 'E:\frontend\node_modules\@mui\styled-engine' React - Material UI | 找不到模块:无法解析“material-ui/Button” - React - Material UI | Module not found: Can't resolve 'material-ui/Button'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM