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

jsxImportSource not working on cra #2752

Closed
testerez opened this issue May 18, 2022 · 3 comments
Closed

jsxImportSource not working on cra #2752

testerez opened this issue May 18, 2022 · 3 comments

Comments

@testerez
Copy link

Current behavior:

I followed the Typescript instructions to add emotion to a fresh create-react-app project: testerez/cra-ts-emotion@086cc35

But when I try to use css prop in any way:

<div>
  <div css={{ color: "red" }}>Hello!</div>
  <div css={css({ color: "red" })}>Hello!</div>
  <div
    css={css`
      color: red;
    `}
  >
    Hello!
  </div>
</div>

Here is the result I get:

<div>
  <div css="[object Object]">Hello!</div>
  <div
    css="You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."
  >
    Hello!
  </div>
  <div
    css="You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."
  >
    Hello!
  </div>
</div>

Did I miss something?

To reproduce:

  1. checkout this sample project https://github.com/testerez/cra-ts-emotion
  2. run npm i && npm run start

Expected behavior:

I would expect the css prop to work with this setup.

Environment information:

  • react version: 18.1.0
  • @emotion/react version: 11.9.0
@Andarist
Copy link
Member

IIRC you need to use an explicit pragma in CRA, see this issue: facebook/create-react-app#9847

@srmagura
Copy link
Contributor

Yes, you need to add /** @jsxImportSource @emotion/react */ to the top of every file where you use the css prop.

Sorry for the confusion — this is an area where we need to improve our documentation (documentation issue here: #2662).

@testerez
Copy link
Author

testerez commented May 18, 2022

Thanks @Andarist and @srmagura , It would be nice if CRA could respect jsxImportSource in tsconfig. It's a bit annoying to have to remember to add this comment on each new file.
I guess I could alternatively use react-app-rewired to setup the emotion babel plugin.

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

3 participants