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

Migration from 11 -> 12 does not include all required changes for @emotion #7050

Closed
paustint opened this issue Sep 18, 2021 · 1 comment · Fixed by #7395
Closed

Migration from 11 -> 12 does not include all required changes for @emotion #7050

paustint opened this issue Sep 18, 2021 · 1 comment · Fixed by #7395
Labels
outdated scope: react Issues related to React support for Nx type: bug

Comments

@paustint
Copy link

paustint commented Sep 18, 2021

The migration update-emotion-setup.ts and use-react-jsx-in-tsconfig.ts include much of the setup, but I still had a lot of problems beyond this since jsxImportSource was not added to tsconfig.

I was previously using the Pragme format as shown below.

/** @jsx jsx */
import { jsx } from '@emotion/react'
...
<div css={css`color: black}>...

After I finally got migrated and npm install worked, I noticed some build errors:

ERROR in libs/ui/src/lib/widgets/ItemSelectionSummary.tsx:37:7
TS2322: Type '{ children: Element; css: SerializedStyles; }' is not assignable to type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'.
  Property 'css' does not exist on type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'.
    35 |   return (
    36 |     <div
  > 37 |       css={css`
       |       ^^^
    38 |         min-height: 20px;
    39 |       `}
    40 |     >

To resolve I had to do the following:

  1. Remove /** @jsx jsx */ from every file that used it
  2. Remove import { jsx } from '@emotion/react' from every file that used it
    3. Update all the .babelrc files to use this format "presets": [["@nrwl/react/babel", { "preset-react": { "runtime": "automatic", "importSource": "@emotion/react" } }]],
  3. Update all the .babelrc files to use this format "presets": [["@nrwl/react/babel", { "runtime": "automatic", "importSource": "@emotion/react" }]],
    "presets": [["@nrwl/react/babel", { "runtime": "automatic", "importSource": "@emotion/react" }]],
  4. Add jsxImportSource": "@emotion/react", to every tsconfig file that had "jsx": "react-jsx", added

It was a pretty painful process and I finally found the last bit of help I needed here: emotion-js/emotion#2111 (comment)

To me, this seems like something that should be part of the migration process, or at least called out as special steps if someone is using the css prop from emotion.

@vsavkin vsavkin added the scope: react Issues related to React support for Nx label Sep 30, 2021
@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: react Issues related to React support for Nx type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants