react-error-boundary: 'ErrorBoundary' cannot be used as a JSX component
Hi guys, I get a strange typescript error when I use the default first example from your lib:
‘ErrorBoundary’ cannot be used as a JSX component, any chance you had seen that before?
react-error-boundaryversion: 3.1.4nodeversion: 14.19.0npmversion: 6.14.16
` import {ErrorBoundary} from ‘react-error-boundary’ function ErrorFallback({error, resetErrorBoundary}) { return ( <div role="alert">
Something went wrong:
{error.message}
<button onClick={resetErrorBoundary}>Try again</button>
</div>
)
}
const ui = (
<ErrorBoundary
FallbackComponent={ErrorFallback}
onReset={() => {
// reset the state of your app so the error doesn’t happen again
}}
<ComponentThatMayError />
</ErrorBoundary>
)
`
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 17
- Comments: 21 (1 by maintainers)
This issue is caused by the breaking change from @types/react v18.
Use command
npm ls @types/reactto see if you have any@types/react@18.xin your dependencies.You can upgrade react v18, or update
@types/react@17.xversion in your lock file.Checkout the solution from these comments:
👋 Very simple solution: this
return this.props.childrenreplace withreturn <>{this.props.children}</>I also have the same issue.
package.json
Upgrading to
"@types/react": "18.0.9"fixed it.Need to upgrade the version of @types/react
I added
to my package.json to pin to @types/react v17 for now
Having the same issue as well
Same issue
upgraded my App’s
@types/reactwhich solved issue.Same here