组件选择器只能与 babel-plugin-emotion 结合使用,使用 emotion 时出错

Component selectors can only be used in conjunction with babel-plugin-emotion error while using emotion

我有一个类似

的样式组件
export const UL = styled.ul`
  list-style: none
`
export const Nav = styled.nav`
  ${UL}: {
    margin-top: 40px;
  }

  background-color: #222;
  padding: 0.35em 1.25em;


`

我运行下面的命令添加babel-plugin-emotion

npm i --save-dev babel-plugin-emotion

我收到这个错误

我还需要做什么才能让插件与情感一起工作?

事实证明,您可以删除模块 babel-plugin-emotion 并使用 emotion 提供的宏。

使用以下导入

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

就是这样,你可以开始了。