Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@emotion/[email protected] does not support nested component pseudo selectors? #2354

Closed
daniellizik opened this issue Apr 19, 2021 · 6 comments

Comments

@daniellizik
Copy link

daniellizik commented Apr 19, 2021

Current behavior:

To reproduce: https://codesandbox.io/s/determined-snowflake-p3d91?file=/src/App.tsx:0-135

import styled from "@emotion/styled";

const Foo = styled.div``;

const Box = styled.div`
  & + ${Foo}::after {
    color: red;
  }
`;

The above results in

Error
Component selectors can only be used in conjunction with @emotion/babel-plugin.

Expected behavior:

Should not throw an error here

Environment information:

dependencies

    "@emotion/babel-plugin": "11.3.0",
    "@emotion/react": "11.1.5",
    "@emotion/styled": "11.1.5",
    "react": "17.0.2",
    "react-dom": "17.0.2",
    "react-scripts": "4.0.0"

.babelrc (setup according to docs) https://emotion.sh/docs/@emotion/babel-plugin

{
  "plugins": [
    "@emotion"
  ]
}
@daniellizik
Copy link
Author

hm, saw this #1768 (comment)

@daniellizik
Copy link
Author

daniellizik commented Apr 19, 2021

the "real" example i have is in a more complicated razzle setup; i'll make some to recreating it

@Andarist
Copy link
Member

Codesandbox doesn't support Babel configuration out of the box, since that React template is CRA-based. You can, however, use our macro variant there (which is basically a way to use our Babel plugin in such config-constrained environments):
https://codesandbox.io/s/angry-greider-9wuy6?file=/src/App.tsx

As you may notice - everything works OK so if something doesn't work on your side then it has to be a tooling issue on your end.

@rarenatoe
Copy link

Whenever I try to use the macro variant, I get this horrible error:

./node_modules/import-fresh/node_modules/resolve-from/index.js
Module not found: Can't resolve 'module' in '/.../project/node_modules/import-fresh/node_modules/resolve-from'

I deleted and reinstalled my node_modules but nothing happened.

@Jacky-Rolo
Copy link

@rarenatoe

Andarist 's another demo work for me, NO NEED @emotion/styled/macro

Andarist, many many thanks your hard work

@cruhl
Copy link

cruhl commented Jan 20, 2022

I am also experiencing this issue and it is preventing my migration from styled-components. I use only TypeScript and do not want to involve Babel, adding { target: "any string at all" } works as shown in the above comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants