React.js – Handle exception caused by import in App.js

I just added an import line to my App.js code that caused an exception which I can see in the dev tools console:

Uncaught SyntaxError: expected expression, got '!'

I've read this page which explains Error Boundaries But adding componentDidCatch() to my App component doesn't help because that will never be executed, as the exception is outside of the App component / App component scope.

It's like I want a componentDidCatch() in my index.js but that index doesn't look like a component to me.

How do I handle a js / React compilation exception gracefully when it is caused by an import statement in App.js?

Maybe I could wrap my App component in AppWrapper component that implements this componentDidCatch() stuff? (or have a InnerAppComponent component) Even if that is a potential solution, I think the question is still valid and I'm wondering if there is a conventional way to deal with this problem (exceptions at the App component level)

I have the same question about my index.js file: what's the convention for handling exceptions there?



Read more here: https://stackoverflow.com/questions/66323710/react-js-handle-exception-caused-by-import-in-app-js

Content Attribution

This content was originally published by Dudeman3000 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: