首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >NPM安装@mui/styles不适用于React 18

NPM安装@mui/styles不适用于React 18
EN

Stack Overflow用户
提问于 2022-06-03 22:14:49
回答 3查看 6.6K关注 0票数 4

我试图将梅花风格安装到React项目中,但是每当我在终端中运行此命令时:

npm i @mui/styles

它读取以下消息:

代码语言:javascript
运行
复制
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: apollo-music-share@0.1.0
npm ERR! Found: react@18.1.0
npm ERR! node_modules/react
npm ERR!   react@"^18.1.0" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^17.0.0" from @mui/styles@5.8.0
npm ERR! node_modules/@mui/styles
npm ERR!   @mui/styles@"*" from the root project

下面是反应中的代码:

代码语言:javascript
运行
复制
import { HeadsetTwoTone } from "@mui/icons-material";
import { AppBar, Toolbar, Typography } from "@mui/material";
import React from "react";
import { makeStyles } from "@mui/styles"

const useStyles = makeStyles(theme => ({
    title: {
        marginLeft: theme.spacing(2)
    }
}))

const Header = () => {
    const classes = useStyles();

    return (
        <AppBar color="secondary" position="fixed">
            <Toolbar>
                <HeadsetTwoTone />
                <Typography className={classes.title} variant="h6" component="h1">
                    Apollo Music Share
                </Typography>
            </Toolbar>
        </AppBar>
    )
}

export default Header;

不幸的是,代码不能工作,因为包不存在,也不会安装。我在网上搜索了一个解决方案,但在这一点上似乎什么工作都没有。

有人知道怎么让这件事发生吗?

非常感谢!

EN

回答 3

Stack Overflow用户

发布于 2022-06-03 22:18:07

npm i @mui/styles --force

它需要一个不同版本的React,但实际上使用React 18很好(从未实际测试过它,但根据我与其他有类似问题的包的经验来看)

票数 5
EN

Stack Overflow用户

发布于 2022-06-05 05:46:39

材料UI (MUI)对反应18不起作用。

你必须降低你对17的反应。

若要将评级下调为17,请运行npm install --save react@17.0.2npm install --save react-dom@17.0.2

这会很完美的!

票数 1
EN

Stack Overflow用户

发布于 2022-09-27 11:50:08

@mui/styles与React.StrictMode不兼容,也不响应18

现在,你有两个选择:

  1. 使用@mui/system - sx道具进行造型(https://mui.com/system/getting-started/overview/)
  2. 使用--force--legacy-peer-deps重试此命令
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72495622

复制
相关文章

相似问题

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