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

Component selectors not working with @emotion/babel-preset-css-prop #1346

Closed
IsenrichO opened this issue May 13, 2019 · 10 comments
Closed

Component selectors not working with @emotion/babel-preset-css-prop #1346

IsenrichO opened this issue May 13, 2019 · 10 comments

Comments

@IsenrichO
Copy link

IsenrichO commented May 13, 2019

  • @emotion/core version: ^10.0.10
  • @emotion/styled version: ^10.0.11
  • @emotion/babel-preset-css-prop version: ^10.0.9
  • react version: ^16.8.4

Relevant code:

import styled from "@emotion/styled";

export const Text = styled.div`
  opacity: 1;
`;

export const Main = styled.div`
  ${Text} {
    color: red;
  }
`;

What you did:
First off, thank you all for your tireless work on the emotion library. It's an excellent set of packages!

In trying to complete the upgrade to emotion v10 in a private codebase. I'm mostly there except for one key issue that I've run into. Namely, component selectors don't seem to be supported when using @emotion/babel-preset-css-prop.

It may be relevant to include that I'm also working in a TypeScript project.

What happened:
Error is thrown. Error message reads:

Uncaught Error: Component selectors can only be used in conjunction with babel-plugin-emotion.

This is an unexpected error because I am using @emotion/babel-preset-css-prop which already uses babel-plugin-emotion under the hood.

Reproduction:
Link to repro

Suggested solution:
Not familiar enough with emotion codebase to recommend a solution but happy to take a crack at it.

@fnky
Copy link

fnky commented May 21, 2019

I have the same issue, but with @emotion/babel-plugin-emotion directly, without the use of @emotion/babel-preset-css-prop.

@IsenrichO
Copy link
Author

@mitchellhamilton @tkh44 (and other maintainers I've missed). I want to thank you all for the incredible work you guys do in making this incredible package! Emotion has been a blessing for my team.

On the topic of this issue, I'm sure you all are busy and so I'm happy to contribute. I'm not too familiar with the codebase, however. Would someone be able to give me some guidance on beginning to fix this?

@fnky
Copy link

fnky commented May 22, 2019

I think I solved the problem on my end. I changed my tsconfig, to use esnext as module output:

{
  "module": "esnext",
  "moduleResolution": "node"
}

And let Babel handle the transpilation of module imports.

@IsenrichO
Copy link
Author

That's actually already what I had in my settings so no luck for me unfortunately. :(

@Andarist
Copy link
Member

Andarist commented Jun 4, 2019

@IsenrichO Your repro is using CRA (codesandbox.io uses its config) - that means that the babelrc you have created there is not even loaded because CRA doesn't support babel config customization. Once I've made this babelrc being loaded (by tweaking node_modules contents - I've removed this) it has started to work.

@IsenrichO
Copy link
Author

Ahh interesting. Thank you @Andarist, that's information I didn't realize. I'm not sure how to edit the CodeSandbox to not apply create-react-app under the hood so I'm not able to easily update my repro to better match the actual environment of my application where I encounter the problem.

However, I do have a different suspicion about why I still have the issue in my app (under GH enterprise, so I can't easily share it unfortunately). We don't use CRA there. Our app uses Lerna where we have a main src package (basically, the application code), a storybook package and a style package. Since we need the same theming available in both the storybook and src packages, we created the style package as a way to export a single styled instance using CreateStyled with our custom theme. We then use it as import styled from '@cms/style'; throughout the monorepo.

Do you think that importing this custom styled instance instead of directly from @emotion/styled could possibly be a cause of the issue? Again, apologies for not being able to provide you with a better repro and thanks for your time.

@Andarist
Copy link
Member

Andarist commented Jun 6, 2019

Yes, that's the most probable problem - there is an open PR which will help you once it gets merged in: #1220 . There is not ETA for this yet though.

@Andarist
Copy link
Member

Closing this right now - because the mentioned #1220 is supposed to fix this and I will be working this month to land this. It will be a part of the upcoming v11 release.

@IsenrichO
Copy link
Author

Nice. Can't wait.

@andreluisce
Copy link

I think I solved the problem on my end. I changed my tsconfig, to use esnext as module output:

{
  "module": "esnext",
  "moduleResolution": "node"
}

And let Babel handle the transpilation of module imports.

Tks that worked for me.

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

No branches or pull requests

4 participants