【问题标题】:Material UI Icon cannot be found in '@mui/icons-material/Send.js'在 \'@mui/icons-material/Send.js\' 中找不到 Material UI 图标
【发布时间】:2022-11-22 13:03:53
【问题描述】:

我正在使用 Material UI 库,我正在尝试使用 import 语句导入 SendIcon

import { SendIcon } from "@mui/icons-material/Send.js";

我必须包含 .js 扩展名,因为我在我的 package.json 文件中包含了 "type" : "module"

但是我收到错误:

export 'SendIcon' (imported as 'SendIcon') was not found in '@mui/icons-material/Send.js' (possible exports: __esModule, default)

我已经为 Material UI 安装了所有必要的模块,但我不确定为什么会出现此错误?

先感谢您!

【问题讨论】:

  • 你检查文档了吗:mui.com/material-ui/material-icons?它显示了如何在单击图标时导入图标。这里显示 SendIcon 是默认导出的。从“@mui/icons-material/Send”导入 SendIcon;没有括号 {}
  • 我从我的 package.json 中删除了 "type":"module",它现在可以工作了。有没有办法让它与 package.json 文件中的 "type":"module" 一起工作?
  • 您是否像我上面提到的那样尝试将其导入为默认值?从“@mui/icons-material/Send.js”导入 SendIcon;
  • 是的,但我收到一个错误:React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object.

标签: javascript reactjs material-ui


【解决方案1】:

代替:

import { SendIcon } from "@mui/icons-material/Send.js";

尝试:

import SendIcon from '@mui/icons-material/Send';

您还可以搜索 Material Icon Page Search for 'Send' 以验证如何正确导入组件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-23
    • 2021-12-10
    • 1970-01-01
    • 2020-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多