首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Material : palette.theme未定义

Material : palette.theme未定义
EN

Stack Overflow用户
提问于 2021-11-26 05:48:26
回答 1查看 1.2K关注 0票数 3

我正在尝试使用mui的List组件,它刚刚安装了所需的依赖项。

错误是

代码语言:javascript
复制
TypeError: theme.palette is undefined
./node_modules/@mui/material/ListItem/ListItem.js/ListItemRoot<
node_modules/@mui/material/ListItem/ListItem.js:85

我的组件非常简单,它只是返回带有ListItem的列表项。组件是由一个带有元素支柱的反应性路由器-dom的路由标记呈现的。

ProductList.jsx

代码语言:javascript
复制
import List from '@mui/material/List'
import ListItem from '@mui/material/ListItem'
import { data } from "./data.json"

export const ProductsList = () => {
    return (
        <List>
            <ListItem>
                content
            </ListItem>
        </List>
    )
}

在重编码路由"/217/cerveza-script“App.js上呈现的组件

代码语言:javascript
复制
import React from 'react';
import {
    Routes,
    Route,
    useLocation
  } from "react-router-dom";
import { AdminHome } from "./admin/AdminHome"
import { NavbarAdmin } from '../components/admin/NavbarAdmin';
import { ClientsView } from "./admin/ClientsView"
import { NewClient } from './admin/NewClient';
import { Profile } from './Profile';
import { Settings } from "./admin/Settings";
import { Employees } from './owner/Employees';
import { OwnerHome } from './owner/OwnerHome';
import { Box } from '@chakra-ui/layout';
import { ProductsList } from '../components/menu/ProductsList';

const App = () => {
    return (
        <Box backgroundColor="gray.50" style={{height: "100vh"}}>
            <NavbarAdmin />
            <Routes>
                <Route exact path="/" element={ <AdminHome />}/>
                <Route exact path="/owner" element={ <OwnerHome />}/>
                <Route path="/clientes" element={ <ClientsView />}/>
                <Route path="/nuevousuario" element={ <NewClient />}/>
                <Route path="/perfil" element={ <Profile/> }/>
                <Route path="/ajustes" element={ <Settings /> }/>
                <Route path="/empleados" element={ <Employees /> }/>
                <Route path="/217/cerveza-script" element={ <ProductsList /> }/>
            </Routes>
        </Box>
    )
};

export default App;

对于其余的ui组件,我也使用ChakraUI (仅对列表和表使用mui )

package.json

代码语言:javascript
复制
{
    "name": "client",
    "version": "0.1.0",
    "private": true,
    "dependencies": {
        "@chakra-ui/icons": "^1.1.1",
        "@chakra-ui/react": "^1.7.2",
        "@emotion/react": "^11.6.0",
        "@emotion/styled": "^11.3.0",
        "@material-ui/core": "^4.12.3",
        "@mui/material": "^5.0.6",
        "@reduxjs/toolkit": "^1.6.2",
        "@testing-library/jest-dom": "^5.15.1",
        "@testing-library/react": "^11.2.7",
        "@testing-library/user-event": "^12.8.3",
        "axios": "^0.24.0",
        "framer-motion": "^4.1.17",
        "react": "^17.0.2",
        "react-dom": "^17.0.2",
        "react-icons": "^4.3.1",
        "react-redux": "^7.2.6",
        "react-router-dom": "^6.0.2",
        "react-scripts": "4.0.3",
        "redux-logger": "^3.0.6",
        "web-vitals": "^1.1.2"
    },
    "scripts": {
        "start": "react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test",
        "eject": "react-scripts eject"
    },
    "eslintConfig": {
        "extends": [
            "react-app",
            "react-app/jest"
        ]
    },
    "browserslist": {
        "production": [
            ">0.2%",
            "not dead",
            "not op_mini all"
        ],
        "development": [
            "last 1 chrome version",
            "last 1 firefox version",
            "last 1 safari version"
        ]
    }
}

编辑:发布错误的package.json

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-11-26 06:48:54

ProductList.js中,从@material-ui/core/而不是@mui/material/导入ListListItem

改变这个,

代码语言:javascript
复制
import List from '@mui/material/List'
import ListItem from '@mui/material/ListItem'

为了这个,

代码语言:javascript
复制
import List from '@material-ui/core/List';    
import ListItem from '@material-ui/core/ListItem';
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70120053

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档