question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

react monorepo shared styles/components: Component selectors can only be used in conjunction with @emotion/babel-plugin

See original GitHub issue

Current behavior:

Currently when attempting to share a style/component from a standard typescript transpiled package to a react app you’re met with Component selectors can only be used in conjunction with @emotion/babel-plugin.

Adding babel to every package is the worst case, it is extremely slow and ideally, we’d use esbuild for everything in the future.

Currently, only the app itself uses babel. This issue still occurs when using something like craco or customize-cra to ensure the plugin for emotion is added to the app build.

To reproduce:

Minimum reproduction repository: https://github.com/Codex-/monorepo-react-emotion-issue

  1. Create a monorepo with npm workspaces and typescript.
  2. Create a package with an exported styled.div.
  3. Create another package that consumes this exported styled.div and exports a simple component for an app to consume.
  4. Create a standard app with create-react-app --template typescript and consume the exported component.
  5. Explode.

Expected behavior:

Component selectors to work when the app uses babel with the plugin without forcing all packages to be coupled with babel.

I suspect the answer based on this will be “use babel for everything or don’t use component selectors”, which would be a huge shame when the gains of using esbuild (as an example) are so massive.

Environment information:

    "@emotion/css": "^11.1.3",
    "@emotion/react": "^11.4.1",
    "@emotion/styled": "^11.3.0",
    "react": "^17.0.2"

Search Terms: npm workspaces Component selectors can only be used in conjunction with @emotion/babel-plugin monorepo Component selectors can only be used in conjunction with @emotion/babel-plugin packages not using babel Component selectors can only be used in conjunction with @emotion/babel-plugin

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
Codex-commented, Oct 3, 2021

Hi, you can choose to use Babel Macros, look the example

Babel macros will only work if you’re using babel.

Is there an agnostic solution? i.e. if I were to use esbuild? Or the stock transpiler?

Babel is egregiously slow.

1reaction
ilchenkoArtemcommented, Sep 29, 2021

I have this error too

Read more comments on GitHub >

github_iconTop Results From Across the Web

Component selectors can only be used in conjunction with ...
I am trying to convert a jss component to styled. ... Component selectors can only be used in conjunction with @emotion/babel-plugin when referencing ......
Read more >
Component selectors can only be used in conjunction with ...
reactjs - Component selectors can only be used in conjunction with babel-plugin-emotion error while using emotion - Stack Overflow. Stack ...
Read more >
FAQs - styled-components
Commonly asked questions about styled-components.
Read more >
Configure Emotion with your Vite React Project
I'm trying to use component selectors in my emotion styles. Did you have any luck doing so? For example, I have this OnOffSwitch...
Read more >
Styled Components - Emotion
styled is a way to create React components that have styles attached to them. ... Component selectors can also be used with object...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found