[英]Material-UI Can't resolve '@material-ui/core/styles/createMuiTheme
I know people have posted similar question on StackOverflow, but nothing worked for me, the errors are not the same nor are the fixes, so I am creating a new post.我知道有人在 StackOverflow 上发布了类似的问题,但对我没有任何帮助,错误不一样,修复也不一样,所以我正在创建一个新帖子。
The firm that is testing me sent me their Github repository and I need to check out that code, it is a Telegram Web app and they are using Material-UI for their design, I cloned the repo installed node_modules
and then I got the error from Material-UI,I followed instructions from other StackOverflow posts but nothing worked for me, uninstalled @material-ui/core
and @material-ui/icons
, installed them again and still got the same error.正在测试我的公司向我发送了他们的 Github 存储库,我需要检查该代码,它是一个 Telegram Web 应用程序,他们正在使用 Material-UI 进行设计,我克隆了 repo 安装的
node_modules
然后我从 Material-UI 得到了错误,我按照其他 StackOverflow 帖子的说明进行操作,但对我没有任何帮助,卸载了@material-ui/core
和@material-ui/icons
,再次安装它们,但仍然出现相同的错误。
I have tried both NPM and Yarn for installation and nothing.我已经尝试了 NPM 和 Yarn 进行安装,但什么也没有。 Hope you can help, it is important.
希望你能帮忙,这很重要。
./src/Theme.js
Module not found: Can't resolve '@material-ui/core/styles/createMuiTheme' in '/Users/Faruk/Desktop/int/telegram-react/src'
If you are using material UI V5 or higher, this works;如果您使用的是 Material UI V5 或更高版本,则此方法有效;
import { createTheme } from '@mui/material/styles';
Don't know about createMuiTheme.不知道 createMuiTheme。 but you can use this for importing Styles in Mui.
但是您可以使用它在 Mui 中导入样式。 This solved mine on importing styles only ,
这仅解决了我的导入样式问题,
import styled from '@material-ui/core';
Also it works for Material-ui Box, Paper, Link, Grid all of them.它也适用于 Material-ui Box、Paper、Link、Grid 所有这些。 Use like this,
像这样使用,
import { Grid, Link, makeStyles, Paper,Box, styled} from '@material-ui/core';
But I'm not sure with your theme .但我不确定你的主题。
As @Ryan mentioned , createMuiTheme
has been renamed to createTheme
in the latest v4 and in v5.正如@Ryan 所提到的,在最新的 v4和 v5 中,
createMuiTheme
已重命名为createTheme
。 See the migration guide here for reference.请参阅此处的迁移指南以供参考。
V5 V5
import { createTheme } from '@mui/material/styles';
V4 V4
import { createTheme } from '@material-ui/core/styles';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.