Skip to content

Commit e30fc15

Browse files
committed
fix: pass module into loadModule
1 parent 9622bba commit e30fc15

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

packages/core/src/utils-hoist/node.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,23 @@ function dynamicRequire(mod: any, request: string): any {
4141
* That is to mimic the behavior of `require.resolve` exactly.
4242
*
4343
* @param moduleName module name to require
44+
* @param existingModule module to use for requiring
4445
* @returns possibly required module
4546
*/
46-
export function loadModule<T>(moduleName: string): T | undefined {
47+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
48+
export function loadModule<T>(moduleName: string, existingModule: any = module): T | undefined {
4749
let mod: T | undefined;
4850

4951
try {
50-
mod = dynamicRequire(module, moduleName);
52+
mod = dynamicRequire(existingModule, moduleName);
5153
} catch (e) {
5254
// no-empty
5355
}
5456

5557
if (!mod) {
5658
try {
57-
const { cwd } = dynamicRequire(module, 'process');
58-
mod = dynamicRequire(module, `${cwd()}/node_modules/${moduleName}`) as T;
59+
const { cwd } = dynamicRequire(existingModule, 'process');
60+
mod = dynamicRequire(existingModule, `${cwd()}/node_modules/${moduleName}`) as T;
5961
} catch (e) {
6062
// no-empty
6163
}

packages/nextjs/src/config/webpack.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ export function constructWebpackConfigFunction(
332332
// Symbolication for dev-mode errors is done elsewhere.
333333
if (!isDev) {
334334
// eslint-disable-next-line @typescript-eslint/no-explicit-any
335-
const { sentryWebpackPlugin } = loadModule<{ sentryWebpackPlugin: any }>('@sentry/webpack-plugin') ?? {};
335+
const { sentryWebpackPlugin } = loadModule<{ sentryWebpackPlugin: any }>('@sentry/webpack-plugin', module) ?? {};
336336

337337
if (sentryWebpackPlugin) {
338338
if (!userSentryOptions.sourcemaps?.disable) {

packages/remix/src/utils/instrumentServer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ const makeWrappedCreateRequestHandler = () =>
301301
export function instrumentServer(): void {
302302
const pkg = loadModule<{
303303
createRequestHandler: CreateRequestHandlerFunction;
304-
}>('@remix-run/server-runtime');
304+
}>('@remix-run/server-runtime', module);
305305

306306
if (!pkg) {
307307
DEBUG_BUILD && logger.warn('Remix SDK was unable to require `@remix-run/server-runtime` package.');

0 commit comments

Comments
 (0)