-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
React 17 + new JSX transform + JSX pragma/pragmaFrag #2041
Comments
U have configured globally the automatic runtime and it cannot be mixed with |
I modified my emotion style components to import the // Typescript
const MyComponent = styled.div`
${(props: any) => props.css}
`;
// Javascript
const MyComponent = styled.div`
${props => props.css}
`; I had to do the following when inheriting from another component: // Typescript
const MyComponent = styled((props: any) => <MyBaseComponent {...props} />)`
${(props: any) => props.css}
`;
// Javascript
const MyComponent = styled(props => <MyBaseComponent {...props} />)`
${props => props.css}
`; @Andarist What is the the recommenced workaround in the interim? I did not have much luck with toolchain / build mods, and certainly don't want to eject the |
@n8sabes just to confirm - you are using a prerelease of CRA 4 and React 17, right? I'm afraid that I don't have a good recommendation for this situation yet. You could create a module like this: #1970 (comment) and use /** @jsx jsx */ vs /** @jsxImportSource @emotion/react */ |
Thanks @Andarist.
I checked out |
facebook/react#20045 |
Hi guys, I am new on react. I have the same issue when i adding @jsx jsx . How can i solve this. `./src/components/UserIcon.tsx
|
Im working on fixing this - from both ends. We have a working PR with the support for new automatic runtimes and im working on a Babel PR to allow old pragmas to overwrite the configured runtime. |
@Metroninja I guess this issue title can be edited to be "React 17" instead of "React 17 RC", now that v17 is out... |
@Andarist do you have links for those PRs for those interested in following along? |
The one in Emotion is here: #1970 |
Edit: The new version of .babelrc {
"presets": [["@emotion/babel-preset-css-prop", { "runtime": "automatic" }]]
} Reference: #2063 For anyone who can use the Babel CSS preset instead of pragmas, this option seems to work:
At least it works with Next.js 10 + React 17... More details here: |
What about Typescript sir? |
@arganaphangquestian This is working with TypeScript as well for me (note the files with Are you or @PabloSzx having issues? |
I've tried with CRA 4 + Typescript but it doesn't work |
Yes, it will not work with It does not have to do with TypeScript. For these environments, a fix is required for the pragma (which is being worked on in the two pull requests above, apparently). |
I've gotten the following to work with CRA4. This tells babel to transpile the file using the old way /** @jsxRuntime classic */
/** @jsx jsx */
import { jsx } from '@emotion/core' |
Yes, this works - but I feel that this is far from ideal and I hope that we can still change the logic for this in Babel, but we'll see. The better news is that with #1970 you should be able to just use this in this CRA4: /** @jsxImportSource @emotion/core */ |
Yes, we only need to prepare a docs update that is being worked on here: #2063 |
I'm going to release |
Thanks @Andarist ! |
Seems like the new versions error out with |
Hey, Thanks for solving this |
Please take a look at the comments in this CRA issue, starting from this comment. Migration everything at once is a little bit problematic, given different release schedules of various tools etc 😢 |
issue: emotion-js/emotion#2041 (comment) ``` 9:50:10 PM: ./components/common/GitHub-Corner.tsx 9:50:10 PM: SyntaxError: /opt/build/repo/components/common/GitHub-Corner.tsx: pragma and pragmaFrag cannot be set when runtime is automatic. 9:50:10 PM: > 1 | /** @jsx jsx */ 9:50:10 PM: | ^ 9:50:10 PM: 2 | import styled from '@emotion/styled' 9:50:10 PM: 3 | import { jsx, css } from '@emotion/core' 9:50:10 PM: 4 | import { mq } from '../variables' 9:50:10 PM: > Build error occurred 9:50:10 PM: Error: > Build failed because of webpack errors 9:50:10 PM: at build (/opt/build/repo/node_modules/next/dist/build/index.js:15:918) 9:50:10 PM: error Command failed with exit code 1. ```
…JSX runtime (#18620) ~~‼️ **Blocked** on #18096 Probably resolved here: #18096 (comment) Ref: emotion-js/emotion#2062 Ref: emotion-js/emotion#2041 (comment) Example upgrade here: upleveled/next-js-example-sep-2020@f46407e
…JSX runtime (vercel#18620) ~~‼️ **Blocked** on vercel#18096 Probably resolved here: vercel#18096 (comment) Ref: emotion-js/emotion#2062 Ref: emotion-js/emotion#2041 (comment) Example upgrade here: upleveled/next-js-example-sep-2020@f46407e
import React from 'react'; |
….html) 💥 ⬆️ Update to emotion-v11 (emotion-js/emotion#2041) 💥 ⬆️ Update react-scripts
…sform (https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html) ♻️ Change to css prop instead of styled components 📝 https://reactjs.org/blog/2020/10/20/react-v17.html 📝 emotion-js/emotion#2041
It looks like emotion is working as an experimental feature. You have to const nextConfig = {
reactStrictMode: true,
experimental: {
emotion: true,
},
}
module.exports = nextConfig and adding {
"compilerOptions": {
"jsxImportSource": "@emotion/react"
},
} I can confirm this works with |
Emotion.jsxを新規作成 先頭に2行分コメントを記述し、古い方式で処理するよう設定 @emotion/reactのjsx、cssと、@emotion/styledのインポート処理を実施 Emotionコンポーネント生成 コンポーネント内でコンテナとタイトルのCSSを定義 コンテナはCSS in JSでの記述、 タイトルはインラインスタイルで記述 ボタンはStyled Componentsで記述し、コンポーネント外で変数を定義 App.jsxにEmotion.jsxのインポート処理を追加 Appコンポーネントの返り値にEmotionコンポーネントを追加 参考URL https://www.udemy.com/course/react_stepup/learn/lecture/24823352 emotion-js/emotion#2041 (comment) https://www.atnr.net/emotion-react-css-prop-error/
Current behavior:
I'm currently using a barebones nextJS deployment with React
17.0.0-rc.3
and have added emotion to the project. I wanted to test out the new JSX transform but I'm running into issues, whenever I setin a component, I run into compilation issues in said file.
SyntaxError: pragma and pragmaFrag cannot be set when runtime is automatic.
my
.babelrc
file but is set below, and the issue is obviously with the value ofruntime
being set to automatic. that said, that's how babel 8 will be set moving forward, and also is what allows the removal of requiringReact
in every file.I'm not sure if here, react, or the babel issues repo was the best to post in but settled here given it's an issue with emotion's setting of the pragma. I suspect a lot of this issue will be popping up soon once react 17 ships, so I thought i'd raise an issue so people aren't lost on day 1 after ripping out all of the 'import React from "react"` across their app and realizing they just made a huge mistake.
Environment information:
react
version: 17.0.0-rc.3emotion
version: 10.0.35The text was updated successfully, but these errors were encountered: