繁体   English   中英

无法将组件选择器与 MUI v5 情感库一起使用

[英]Can't use Component Selectors with MUI v5 Emotion Library

import { Box, styled } from "@mui/material"
import { Body1 } from "elements/Typography"
export const ItemHeader = styled(Box)`
  display: flex;
  flex-direction: column;
  gap: 1em;

  ${Body1} {
    span {
      margin-left: 0.5em;
      font-weight: 500;
      color: ${({ theme }) => theme.palette.error.main};
    }
  }
`

我正在使用组件选择器创建一个 mui 情感组件,我已经设置了 babel.config.js并安装了 @emotion/babel-plugin

module.exports = {
  plugins: [
    [
      "@emotion",
      {
        importMap: {
          "@mui/system": {
            styled: {
              canonicalImport: ["@emotion/styled", "default"],
              styledBaseImport: ["@mui/system", "styled"]
            }
          },
          "@mui/material/styles": {
            styled: {
              canonicalImport: ["@emotion/styled", "default"],
              styledBaseImport: ["@mui/material/styles", "styled"]
            }
          }
        }
      }
    ]
  ]
};

但它抛出以下错误

1

你试过了吗

import styled from "@emotion/styled/macro";

或者

import styled from "@emotion/styled";

代替

import {styled } from "@mui/material";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM