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.

Component selectors can only be used in conjunction

See original GitHub issue

Hello following the docs to use the styled, but I got the following error:

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

code:


import styled from '@emotion/styled';
import { flexCenter, mxw80, flex, flexAlignCenter } from '../../globals/flex';
export const IconContainer = styled.div``;
export const SearchContainer = styled.div`
  display: inline-flex;
  align-items: center;
  flex: 0 1 350px;
  border: 1px solid #ccc;
  border-radius: 25px;
  overflow: hidden;
  height: 55px;
  background: white;
  ${IconContainer} {
    ${flexAlignCenter}
    width: 50px;
    padding: 0.5rem;
    height: 100%;
  }
  & > input {
    width: calc(100% - 50px);
    height: 100%;
    border: 0;
    padding: 0.5rem 0.5rem 0.5rem 0;
    outline: none;
  }
`;

jsx:

      <SearchContainer>
        <IconContainer>
          <FontAwesomeIcon
            className="searchIcon"
            icon={faSearch}
            size="lg"
            fixedWidth
            color="#1976d2"
          />
        </IconContainer>
        <input></input>
      </SearchContainer>

.babelrc:

{
  "plugins": [
    [
      "emotion",
      {
        // sourceMap is on by default but source maps are dead code eliminated in production
        "sourceMap": true,
        "autoLabel": process.env.NODE_ENV !== "production",
        "labelFormat": "[local]",
        "cssPropOptimization": true
      }
    ]
  ],
  "presets": [
    [
      "@emotion/babel-preset-css-prop",
      {
        "autoLabel": true,
        "labelFormat": "[local]"
      }
    ]
  ]
}

I looked for this error and found no solution

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

31reactions
Andaristcommented, Feb 18, 2020

This codesandbox is using Create React App template and you can’t customize babel plugins with that. This is, by design, not allowed when using CRA.

However they support Babel macros and we provide one, so if you make this change:

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

This starts to work as expected.

0reactions
rarenatoecommented, Jun 18, 2021

using @emotion/styled/macro throws me the following eslint error:

./node_modules/import-fresh/node_modules/resolve-from/index.js
Module not found: Can't resolve 'module' in '/Users/.../Documents/BVDash/bvdash-web/node_modules/import-fresh/node_modules/resolve-from'
Read more comments on GitHub >

github_iconTop Results From Across the Web

Component selectors can only be used in conjunction with ...
Component selectors can only be used in conjunction with @emotion/babel-plugin, the swc Emotion plugin, or another Emotion-aware compiler transform. Seeing the ...
Read more >
Component selectors can only be used in conjunction with ...
Component selectors can only be used in conjunction with babel-plugin-emotion error while using emotion · Ask Question. Asked 2 years, 8 months ...
Read more >
Component selectors can only be used in conjunction with ...
Coding example for the question Component selectors can only be used in conjunction with babel-plugin-emotion error while using emotion-Reactjs.
Read more >
emotion/babel-plugin
Allows an emotion component to be used as a CSS selector. Minification, ✓, Any leading/trailing space between properties in your css and styled...
Read more >
[Next.js] Component selectors can only be used in conjunction ...
[Next.js] Component selectors can only be used in conjunction 이슈 · body · div · p · div ...
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