简体   繁体   English

Material-UI 无法解析 '@material-ui/core/styles/createMuiTheme

[英]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.

相关问题 导入错误:在使用 @material-ui/core/styles/ThemeProvider/ 和 @material-ui/core/styles/createMuiTheme/ 时找不到模块 - import error: Module not found on using @material-ui/core/styles/ThemeProvider/ and @material-ui/core/styles/createMuiTheme/ "未找到模块:无法解析“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' 无法解析模块 - Material-UI - Can' t resolve module - Material-UI 无法解析“材料界面/按钮” - Can't resolve 'material-ui/Button' Material-ui:找不到模块:无法解析“material-ui/Toolbar” - Material-ui: Module not found: Can't resolve 'material-ui/Toolbar' 找不到模块:无法在React中解析'@ material-ui / core / RaisedButton' - Module not found: Can't resolve '@material-ui/core/RaisedButton' in React 如何解决找不到模块:无法在 Material-UI 中解析“@babel/runtime/core-js/map” - How to solve Module not found: Can't resolve '@babel/runtime/core-js/map' in Material-UI 使用 Typescript 将属性添加到 Material-UI 的 createMuiTheme 中的背景道具 - Add property to background prop in createMuiTheme in Material-UI using Typescript 找不到模块:无法解析“./node_modules/@material-ui/core/IconButton” - Module not found: Can't resolve './node_modules/@material-ui/core/IconButton'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM