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.

TypeError : 'Component' cannot be used as JSX component

See original GitHub issue

Verify canary release

  • I verified that the issue exists in Next.js canary release

Provide environment information

Operating System: Platform: linux Arch: x64 Version: #1 SMP Wed Aug 25 23:20:18 UTC 2021 Binaries: Node: 14.18.2 npm: 8.3.0 Yarn: 1.22.17 pnpm: N/A Relevant packages: next: 12.1.6 react: 17.0.2 react-dom: 17.0.2

Which example does this report relate to?

with-redux

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

I am using nextjs example with-redux . The current version of devDependencies @types/react and @types/react-dom gives type error Type Error 'Component' cannot be used as a JSX component.
Below is screenshot showing error

Screenshot (19)

The problem can be solved by upgrading the @types/react and @types/react-dom dependencies

Expected Behavior

TypeError should not occur

To Reproduce

If you do not see the typeError after cloning this example repository run next build to see typeError while build process .

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:5
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
codemilecommented, Jun 7, 2022

This workaround is to add a resolution section to your package.json to ensure the correct TS defs were installed.

"resolutions": {
    "**/@types/react": "^17.0.21",
    "**/@types/react-dom": "^17.0.9"
}

You can change the above versions to which ever ones you’re using on your project.

I haven’t fully tested the above, but it seems to have worked for me on a quick test.

Note: I had to delete my node_modules and reinstall for this to work. Yarn doesn’t seem to pick up on resolution changes, and also notice that the paths are prefixed with “**/” to capture deep dependencies.

2reactions
saurabhmehta1601commented, Jun 3, 2022

Upgrading these depencencies solves the issue :

    "@types/react": "^18.0.10",
    "@types/react-dom": "^18.0.5"
Read more comments on GitHub >

github_iconTop Results From Across the Web

Component cannot be used as a JSX component. Its return ...
Another common cause of the "Component cannot be used as a JSX component" error is when we return anything other ...
Read more >
Component from NPM module cannot be used as a JSX ...
This is what the type error looks like: 'Component'(Name here) cannot be used as a JSX component. Its return type 'Element[]' is not...
Read more >
[Solved] NPM package cannot be used as a JSX component
The NPM package cannot be used as a JSX component error occurs if you have installed multiple versions of @types/react package, ...
Read more >
component cannot be used as a jsx component. - You.com
Component cannot be used as a JSX component. Its return type 'Element[]' is not a valid JSX element. 79,182 Solution 1. A component...
Read more >
Component cannot be used as a JSX component. Its return ...
[Solved]-Component cannot be used as a JSX component. Its return type 'Element[]' is not a valid JSX element-Reactjs ... In case anyone is...
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