diff --git a/src/webpack/patchWebpack.ts b/src/webpack/patchWebpack.ts index d1431ba8d..6110c9344 100644 --- a/src/webpack/patchWebpack.ts +++ b/src/webpack/patchWebpack.ts @@ -281,7 +281,7 @@ function patchFactory(id: PropertyKey, factory: ModuleFactory) { if (!patch.all) patches.splice(i--, 1); } - const patchedFactory: PatchedModuleFactory = (module, exports, require) => { + const patchedFactory: PatchedModuleFactory = function (module, exports, require) { for (const moduleFactories of allModuleFactories) { Object.defineProperty(moduleFactories, id, { value: patchedFactory.$$vencordOriginal, @@ -297,17 +297,17 @@ function patchFactory(id: PropertyKey, factory: ModuleFactory) { logger.error("WebpackRequire was not initialized, running modules without patches instead."); } - return void originalFactory(module, exports, require); + return void originalFactory.call(this, module, exports, require); } try { - factory(module, exports, require); + factory.call(this, module, exports, require); } catch (err) { // Just rethrow Discord errors if (factory === originalFactory) throw err; logger.error("Error in patched module", err); - return void originalFactory(module, exports, require); + return void originalFactory.call(this, module, exports, require); } // Webpack sometimes sets the value of module.exports directly, so assign exports to it to make sure we properly handle it diff --git a/src/webpack/wreq.d.ts b/src/webpack/wreq.d.ts index c86fa1c49..c810c5a56 100644 --- a/src/webpack/wreq.d.ts +++ b/src/webpack/wreq.d.ts @@ -13,7 +13,7 @@ export type Module = { }; /** exports can be anything, however initially it is always an empty object */ -export type ModuleFactory = (module: Module, exports: ModuleExports, require: WebpackRequire) => void; +export type ModuleFactory = (this: ModuleExports, module: Module, exports: ModuleExports, require: WebpackRequire) => void; export type AsyncModuleBody = ( handleDependencies: (deps: Promise[]) => Promise & (() => void)