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.

Type error: 'SimpleBar' cannot be used as a JSX component.

See original GitHub issue

I am getting an error during the NextJS build process like in below:

Type error: 'SimpleBar' cannot be used as a JSX component.

I am using ^2.3.6 as simplebar-react version.

How can I fix this?

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:16
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
OchreFoxcommented, Jul 26, 2022

Here’s a workaround for people looking for a solution: I installed react-beautiful-dnd and also got the same error:

'SimpleBar' cannot be used as a JSX component.
  Its instance type 'SimpleBar' is not a valid JSX element.
    The types returned by 'render()' are incompatible between these types.
      Type 'React.ReactNode' is not assignable to type 'import("./node_modules/@types/react-beautiful-dnd/node_modules/@types/react/index").ReactNode'.
        Type '{}' is not assignable to type 'ReactNode'.

I managed to track the error and this dependency introduced types for react in v18. For context, I’m using Typescript with React 17 since I have some dependencies that are not fully compatible with v18. This is the command output:

npm ls @types/react
ROOT-PROJECT@1.0.0 <PROJECT_PATH>
├─┬ @types/react-beautiful-dnd@13.1.2
│ └── @types/react@18.0.15
├─┬ @types/react-dom@17.0.17 extraneous
│ └── @types/react@17.0.45 extraneous
├─┬ @types/react-window@1.8.5

Now the only thing to be done is to override this dependency when installing. In npm is done by forcing the dependency version in the overrides section in the package.json file. I’m using yarn v1 so the directive is called resolutions:

 "resolutions": {
    "@types/react": "17.0.39"
  },

After modifying the package.json file and running yarn install, I restarted VS Code and the error is now gone.

0reactions
GitHub-Coolcommented, Nov 10, 2022

Here’s a workaround for people looking for a solution: I installed react-beautiful-dnd and also got the same error:

'SimpleBar' cannot be used as a JSX component.
  Its instance type 'SimpleBar' is not a valid JSX element.
    The types returned by 'render()' are incompatible between these types.
      Type 'React.ReactNode' is not assignable to type 'import("./node_modules/@types/react-beautiful-dnd/node_modules/@types/react/index").ReactNode'.
        Type '{}' is not assignable to type 'ReactNode'.

I managed to track the error and this dependency introduced types for react in v18. For context, I’m using Typescript with React 17 since I have some dependencies that are not fully compatible with v18. This is the command output:

npm ls @types/react
ROOT-PROJECT@1.0.0 <PROJECT_PATH>
├─┬ @types/react-beautiful-dnd@13.1.2
│ └── @types/react@18.0.15
├─┬ @types/react-dom@17.0.17 extraneous
│ └── @types/react@17.0.45 extraneous
├─┬ @types/react-window@1.8.5

Now the only thing to be done is to override this dependency when installing. In npm is done by forcing the dependency version in the overrides section in the package.json file. I’m using yarn v1 so the directive is called resolutions:

 "resolutions": {
    "@types/react": "17.0.39"
  },

After modifying the package.json file and running yarn install, I restarted VS Code and the error is now gone.

It worked

Read more comments on GitHub >

github_iconTop Results From Across the Web

Component cannot be used as a JSX component in React
The error Component cannot be used as a JSX component occurs for multiple reasons, returning an array of JSX elements instead of a...
Read more >
Component cannot be used as a JSX component. Its return ...
js to App.tsx, I met the same error for component named Section. The solution for me was a component type React.Fc<{...}> ...
Read more >
Component from NPM module cannot be used as a JSX ...
Its return type 'Element[]' is not a valid JSX element. ... otherwise an error wouldn't be thrown because React allows an array to...
Read more >
simplebar-react - npm
React component for SimpleBar. Latest version: 2.4.3, last published: 3 months ago. Start using simplebar-react in your project by running ...
Read more >
'SVG' cannot be used as a JSX component.
Its instance type 'InlineSVG' is not a valid JSX element. The types returned by 'render()' are incompatible between these types. Type 'React.ReactNode' 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