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

NextJS: 'Box' cannot be used as a JSX component. #2430

Closed
nesterow opened this issue Jun 5, 2023 · 5 comments · Fixed by #2432
Closed

NextJS: 'Box' cannot be used as a JSX component. #2430

nesterow opened this issue Jun 5, 2023 · 5 comments · Fixed by #2432
Labels
released This issue/pull request has been released.

Comments

@nesterow
Copy link

nesterow commented Jun 5, 2023

Describe the bug
The problems appear on next build and seem to be related to all theme-ui/Box components:

./src/components/cards/Post.tsx:33:18
Type error: 'Heading' cannot be used as a JSX component.
  Its return type 'ReactNode' is not a valid JSX element.

Screenshots
This is what might cause the error:

return <Component ref={ref} css={style} {...rest} />

image

'Component' cannot be used as a JSX component.
  Its element type 'ReactElement<any, any> | Component<any, any, any> | null' is not a valid JSX element.
    Type 'Component<any, any, any>' is not assignable to type 'Element | ElementClass | null'.
      Type 'Component<any, any, any>' is not assignable to type 'ElementClass'.
        The types returned by 'render()' are incompatible between these types.
          Type 'React.ReactNode' is not assignable to type 'import("/media/anton/Enterprise1/nesterov.digital/node_modules/@types/react/index").ReactNode'.
            Type 'ReactElement<any, string | JSXElementConstructor<any>>' is not assignable to type 'ReactNode'.
              Property 'children' is missing in type 'ReactElement<any, string | JSXElementConstructor<any>>' but required in type 'ReactPortal'.ts(2786)

Additional context

  • OS: Ubuntu 22.10
  • NodeJS v18.16.0
  • package.json:
    "next": "13.4.4"
    "@types/node": "20.2.5"
    "@types/react": "18.2.8"
    "@types/react-dom": "18.2.4"
    
  • tsconfig.json
    "jsxImportSource": "theme-ui",
    
@nesterow
Copy link
Author

nesterow commented Jun 5, 2023

Currently solved by ignoreBuildErrors:

next.config.js


/** @type {import('next').NextConfig} */
const nextConfig = {
    pageExtensions: ['js', 'jsx', 'ts', 'tsx'],
    typescript: {
        // !! WARN !!
        // Dangerously allow production builds to successfully complete even if
        // your project has type errors.
        // !! WARN !!
        ignoreBuildErrors: true,
    },
}

module.exports = nextConfig

@hasparus
Copy link
Member

Hey @nesterow. Thanks for the issue! Just wanted to let you know I reproduced it and I'm working on it.

It might be related to TypeScript 5.1 JSX changes. Not 100% sure yet, but it should be just an update to the types.

https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-1.html#decoupled-type-checking-between-jsx-elements-and-jsx-tag-types

@hasparus
Copy link
Member

Okay, it seems like you need TypeScript 5 to use the newest @types/react.

The error of ReactNode not being JSX.Element comes from the fact that TypeScript 5.1.2 is breaking, and @types/react in DT isn’t semverred, it’s locked to React types.

DefinitelyTyped/DefinitelyTyped#65135

@hasparus hasparus added the prerelease This change is available in a prerelease. label Jun 15, 2023
@hasparus
Copy link
Member

🚀 Issue was released in v0.16.0 🚀

@hasparus hasparus added released This issue/pull request has been released. and removed prerelease This change is available in a prerelease. labels Jun 15, 2023
@nesterow
Copy link
Author

nesterow commented Jun 15, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released This issue/pull request has been released.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants