question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TS2322: 'css' does not exist on type 'DetailedHTMLProps...' with new JSX runtime w/ NextJs

See original GitHub issue

Current 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:

  1. clone this repo: https://github.com/Project-Setup/Nextjs_Ts_Eslint
  2. run script in the project folder
nvm use || nvm install
npm install
npm run build
  1. 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.0
  • nextjs version: 10.0.1
  • typescript: 4.0.5

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

21reactions
Andaristcommented, Nov 24, 2020

Please just apply this patch:

diff --git a/tsconfig.json b/tsconfig.json
index c8399a6..983beb9 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -21,7 +21,8 @@
     "moduleResolution": "node",
     "resolveJsonModule": true,
     "isolatedModules": true,
-    "jsx": "preserve",
+    "jsx": "react-jsx",
+    "jsxImportSource": "@emotion/react",
     "baseUrl": "./src"
   },
   "include": [

This probably ain’t mentioned anywhere in the docs - if you’d like to prepare one I would appreciate a PR for this.

4reactions
Andaristcommented, Nov 24, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found