Fix CheckBoxTree rendering by aliasing react-checkbox-tree to its ESM bundle#9989
Fix CheckBoxTree rendering by aliasing react-checkbox-tree to its ESM bundle#9989dpage wants to merge 1 commit into
Conversation
react-checkbox-tree v2 marks the package as "type": "module" but its "require" exports condition still points at a UMD bundle. babel-loader turns our ESM imports into require() calls, so webpack picks the UMD file and treats it as ESM (because of "type": "module"). The UMD wrapper's module.exports = factory(...) never runs in that context, and the default export ends up undefined - causing CheckBoxTree to render "Element type is invalid" in dialogs like Import/Export Servers. Alias react-checkbox-tree to its ESM bundle (lib/index.esm.js, exposed by the package's own "./*": "./*" exports map) so webpack picks the file that actually has a default export. Closes pgadmin-org#9972
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughA webpack alias configuration is added to ChangesWebpack Alias for react-checkbox-tree
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
react-checkbox-treev2 (bumped to^2.0.1in fix: Bump runtime and development dependencies #9870) marks the package as"type": "module"while still pointing itsrequireexports condition at a UMD bundle. Babel transforms ourimportstatements torequire(), so webpack picks the UMD file and then treats it as ESM (because of"type": "module"). The UMD wrapper'smodule.exports = factory(...)never runs in that context and the default export isundefined— which is why dialogs that mountCheckBoxTree(Tools → Import/Export Servers and similar) fail with "Element type is invalid".resolve.aliasforreact-checkbox-treepointing at the package's ESM bundle (lib/index.esm.js). That file is explicitly exposed by the package's own"./*": "./*"exports passthrough, has a real default export, and is what webpack would have picked if our build didn't down-transform imports to requires.$suffix makes it an exact-match alias, so any future subpath imports (e.g. CSS) continue to resolve normally.Test plan
yarn run linter— cleanyarn run jest— all 140 suites / 824 tests passyarn run bundle:devandyarn run bundleboth compile cleanly (only the pre-existing asset-size advisory warnings)app.bundle.jscontainednode_modules/react-checkbox-tree/lib/index.js(the UMD wrapper); after the fix, onlylib/index.esm.jsis bundled and thewebpackUniversalModuleDefinitionwrapper is goneCloses #9972
Summary by CodeRabbit