【问题标题】:styled-components/macro isn't working with CRAstyled-components/macro 不适用于 CRA
【发布时间】:2022-01-08 08:22:54
【问题描述】:

当我安装新的 create-react-app 并添加 babel-plugin-styled-components 并将 displayName 选项添加到 babel-plugin-macros.config.js 时,它不会像文档中那样添加可读的类名 -> https://styled-components.com/docs/tooling#babel-macro

这是一个配置为https://github.com/Futekov3216/CRA.git的回购

P.S 我不想弹出

【问题讨论】:

  • 请提供足够的代码,以便其他人更好地理解或重现问题。

标签: styled-components


【解决方案1】:

今天我自己也遇到了这样的问题。问题在于styled-components 本身。样式中的宏从 5.2.2 版本开始不起作用,不知道何时修复。最简单的解决方案:

npm i styled-components@5.2.1

【讨论】:

  • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
【解决方案2】:

这个问题在 styled-components v5.3.3 中仍然存在。访问this 以了解有关该问题的更多信息。此时,您可以安装 @mxpv 提到的 styled-components@5.2.1 以获取组件的名称以及生成的类。

【讨论】:

  • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 1970-01-01
  • 2021-12-25
  • 2020-10-19
  • 2021-09-19
  • 1970-01-01
  • 2021-08-25
  • 2019-05-30
  • 2017-11-01
  • 1970-01-01
相关资源
最近更新 更多