TS2322: 'css' does not exist on type 'DetailedHTMLProps...' with new JSX runtime w/ NextJs
See original GitHub issueCurrent behavior:
I have used NextJs v10.0.1 and emotionJs v11.0.0. I installed the @emotion/babel-plugin
and followed the new jsx runtime setup with NextJs in this page.
{
"presets": [
[
"next/babel",
{
"preset-react": {
"runtime": "automatic",
"importSource": "@emotion/react"
}
}
]
],
"plugins": ["@emotion/babel-plugin"]
}
I still get errors when input css
properties in the JSX react element.
(JSX attribute) css: SerializedStyles
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>'.ts(2322)
To reproduce:
- clone this repo: https://github.com/Project-Setup/Nextjs_Ts_Eslint
- run script in the project folder
nvm use || nvm install
npm install
npm run build
- get an error on the build step
> Nextjs_Ts_Eslint@1.0.0 build
> next build
Failed to compile.
./src/pages/index.tsx:21:12
Type error: 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>'.
19 | <div>
20 | <Global styles={globalBodyStyles} />
> 21 | <div css={indexPageStyles}>
| ^
22 | <h1 css={titleStyles}>Project Setup</h1>
23 | </div>
24 | </div>
info - Creating an optimized production build .npm ERR! code 1
Expected behavior:
Babel should map css
properties in JSX elements and typescript should not output type error TS2322 for css
in JSX elements.
Environment information:
react
version: 17.0.1@emotion/react
version: 11.0.0nextjs
version: 10.0.1typescript
: 4.0.5
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
reactjs - error TS2322: Property 'css' does not exist on type ...
Property 'css' does not exist on type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'. Here is a basic code example: import ...
Read more >property 'css' does not exist on type 'detailedhtmlprops - You.com ...
Moderate. Strict. Open links in a new tab ... error TS2322: Property 'css' does not exist on type ... with new JSX runtime...
Read more >How to Use class instead of className with Preact and ...
I'm just going to discuss how I made my way to this solution as an intermediate TypeScript user, since this is a learning...
Read more >typescript Code Example - Code Grepper
Source: typescript.bootcss.com ... Property 'name' does not exist on type '{ firstName: string; lastName: string; role: string ... img.src = chrome.runtime.
Read more >styled-jsx - npm
There are 561 other projects in the npm registry using styled-jsx. ... High-performance runtime-CSS-injection when not server-rendering ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Please just apply this patch:
This probably ain’t mentioned anywhere in the docs - if you’d like to prepare one I would appreciate a PR for this.
Oh - I haven’t realized that
next
enforces this. From what I looked up in their code they don’t really use TS for transpiling at all so I’m not sure why do they insist on this value 🤷♂️I have also thought that
"jsx": "react-jsx"
is required for"jsxImportSource"
but it seems that it isn’t - the latter works without the former when it comes to the JSX namespace lookup.