【问题标题】:Material-UI Can't resolve '@material-ui/core/styles/createMuiThemeMaterial-UI 无法解析 '@material-ui/core/styles/createMuiTheme
【发布时间】:2021-10-24 22:16:48
【问题描述】:

我知道有人在 StackOverflow 上发布了类似的问题,但对我没有任何帮助,错误也不相同,修复也不相同,所以我正在创建一个新帖子。

测试我的公司向我发送了他们的 Github 存储库,我需要检查该代码,这是一个 Telegram Web 应用程序,他们正在使用 Material-UI 进行设计,我克隆了安装的 repo node_modules 然后我从 Material-UI 收到错误,我按照其他 StackOverflow 帖子的说明进行操作,但对我没有任何效果,卸载了 @material-ui/core@material-ui/icons,再次安装它们,但仍然出现同样的错误。

我已经尝试过 NPM 和 Yarn 的安装,但没有。希望你能帮忙,这很重要。

./src/Theme.js
Module not found: Can't resolve '@material-ui/core/styles/createMuiTheme' in '/Users/Faruk/Desktop/int/telegram-react/src'

【问题讨论】:

  • 您使用的是什么版本的 Material-UI?
  • 版本是@material-ui/core@4.12.3
  • 我认为问题在于另一个开发人员没有正确导入它,我使用了不同的导入并且它工作但现在在导入 import { c̶r̶e̶a̶t̶e̶M̶u̶i̶T̶h̶e̶m̶e̶ } 上的 createMuiTheme 上有删除线来自“@material-ui /core/styles";
  • 这是因为在 v5 中名称更改为 createTheme,所以在最新版本的 v4 中,两个名称都被导出,但 createMuiThemedeprecated

标签: javascript html css reactjs material-ui


【解决方案1】:

不知道 createMuiTheme。但您可以使用它在 Mui 中导入样式。这解决了我的仅导入样式

import styled from '@material-ui/core';

它也适用于 Material-ui Box、Paper、Link、Grid 所有这些。像这样使用,

import { Grid, Link, makeStyles, Paper,Box, styled} from '@material-ui/core';

但我不确定你的主题

【讨论】:

    【解决方案2】:

    作为 @Ryan mentionedcreateMuiThemelatest v4 和 v5 中已重命名为 createTheme。请参阅迁移指南here 以供参考。

    V5

    import { createTheme } from '@mui/material/styles';
    

    V4

    import { createTheme } from '@material-ui/core/styles';
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-14
      • 2021-11-16
      • 1970-01-01
      • 2020-05-04
      • 2021-05-05
      • 2018-09-19
      • 2018-09-14
      • 1970-01-01
      相关资源
      最近更新 更多