-
-
Notifications
You must be signed in to change notification settings - Fork 315
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
[React] improve error handling in resolveReactComponent #2006
base: 2.x
Are you sure you want to change the base?
[React] improve error handling in resolveReactComponent #2006
Conversation
53f7119
to
a312fee
Compare
Alternatively function const importAllReactComponents = (r: __WebpackModuleApi.RequireContext) => {
- r.keys().forEach((key) => (reactControllers[key] = r(key).default));
+ r.keys().forEach((key) => {
+ if (r(key).default !== undefined) {
+ reactControllers[key] = r(key).default;
+ }
+ });
}; However, with these changes, it will be more difficult to determine if a module or default export is missing. |
throw new Error( | ||
`React controller "${name}" could not be resolved. Ensure the module exports the controller as default.` | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw new Error( | |
`React controller "${name}" could not be resolved. Ensure the module exports the controller as default.` | |
); | |
throw new Error(`React controller "${name}" could not be resolved. Ensure the module exports the controller as default.`); |
Hi @teklakct ! Thanks for this Could you rebuild the JS dist files ? (that's the reason of the CI failure) From the root of the monorepo: (you may need to rebase before) |
WHAT
Improve error handling and readability in
window.resolveReactComponent
functionWith those changes, when resolving a module with no default export, an error message with a hint will be shown:
WHY
I found that when someone creates a module without a default export then the error message is quite confusing.
For example:
Whenever there will be an element like this
An error like below in console appear:
Which is not exactly true. The module
NoDefaultExportComponent
was found but there is no required default export.