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

[BUG] 'AppInsightsErrorBoundary' cannot be used as a JSX component. #29

Closed
kkazala opened this issue Jan 24, 2023 · 4 comments
Closed
Assignees

Comments

@kkazala
Copy link

kkazala commented Jan 24, 2023

Description/Screenshot

I have a SPFx 1.16 solution: https://github.com/kkazala/codespaceSPFx created using yo @microsoft/sharepoint
I want to add ErrorBoundary as described here: https://learn.microsoft.com/en-us/azure/azure-monitor/app/javascript-react-plugin#react-error-boundaries

I'm getting the following error:

'AppInsightsErrorBoundary' cannot be used as a JSX component.
  Its instance type 'AppInsightsErrorBoundary' is not a valid JSX element.
    Type 'AppInsightsErrorBoundary' is missing the following properties from type 'ElementClass': context, setState, forceUpdate, props, refs

I understand it may be related to the react version, but SPFx requires React v17.0.1 SPFx development environment compatibility

Steps to Reproduce
Repo contains codespace configuration files, please simply create a new codepsace from the repo

  • OS/Browser:
  • React Version: 17.0.1
  • SDK Version [e.g. 22]: 3.4.0
  • How you initialized the SDK:

Expected behavior
I would expect no errors =)

Additional context
I am aware I didn't instantiate ApplicationInsights ;) This is just an example presenting the issue with AppInsightsErrorBoundary.

@kkazala
Copy link
Author

kkazala commented Jan 30, 2023

Adding constructor:

export default class AppInsightsErrorBoundary extends React.Component<IAppInsightsErrorBoundaryProps, IAppInsightsErrorBoundaryState> {
    constructor(props: IAppInsightsErrorBoundaryProps | Readonly<IAppInsightsErrorBoundaryProps>) {
        super(props);
        this.state = { hasError: false };
    }
   [...]

would solve the issue. Could you look into it?

@Karlie-777
Copy link
Contributor

@kkazala Thanks for suggested solutions! do you mind trying adding "allowSyntheticDefaultImports": true, to your tsconfig.json? (I didn't find this config in your project, correct me if I am wrong) since React didn't export default and this may lead to complier errors as well

@kkazala
Copy link
Author

kkazala commented Jan 31, 2023

@Karlie-777 Awesome, it's all working now 😊
thank you for your help!

@kkazala kkazala closed this as completed Jan 31, 2023
Copy link

github-actions bot commented Feb 1, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants