diff --git a/src/webpack/common/menu.ts b/src/webpack/common/menu.ts index 32b4d565..c2e84d19 100644 --- a/src/webpack/common/menu.ts +++ b/src/webpack/common/menu.ts @@ -23,12 +23,19 @@ export const Menu = {} as t.Menu; // Relies on .name properties added by the MenuItemDemanglerAPI waitFor(m => m.name === "MenuCheckboxItem", (_, id) => { - // we have to do this manual require by ID because m is in this case the MenuCheckBoxItem instead of the entire module - const module = wreq(id); + // We have to do this manual require by ID because m in this case is the MenuCheckBoxItem instead of the entire module + const exports = wreq(id); - for (const e of Object.values(module)) { - if (typeof e === "function" && e.name.startsWith("Menu")) { - Menu[e.name] = e; + for (const exportKey in exports) { + // Some exports might have not been initialized yet due to circular imports, so try catch it. + try { + var exportValue = exports[exportKey]; + } catch { + continue; + } + + if (typeof exportValue === "function" && exportValue.name.startsWith("Menu")) { + Menu[exportValue.name] = exportValue; } } }); diff --git a/src/webpack/patchWebpack.ts b/src/webpack/patchWebpack.ts index 2c212a9a..e9b05069 100644 --- a/src/webpack/patchWebpack.ts +++ b/src/webpack/patchWebpack.ts @@ -442,7 +442,12 @@ function runFactoryWithWrap(patchedFactory: PatchedModuleFactory, thisArg: unkno } for (const exportKey in exports) { - const exportValue = exports[exportKey]; + // Some exports might have not been initialized yet due to circular imports, so try catch it. + try { + var exportValue = exports[exportKey]; + } catch { + continue; + } if (exportValue != null && filter(exportValue)) { waitForSubscriptions.delete(filter); diff --git a/src/webpack/webpack.ts b/src/webpack/webpack.ts index 26d9c0d7..fd15d9f7 100644 --- a/src/webpack/webpack.ts +++ b/src/webpack/webpack.ts @@ -156,7 +156,14 @@ export function _blacklistBadModules(requireCache: NonNullable