Skip to content

Commit ff18dfd

Browse files
authored
fix(nextjs): Resolve path for dynamic webpack import (#13751)
1 parent e45566d commit ff18dfd

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

packages/nextjs/src/config/webpack.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,8 @@ 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('@sentry/webpack-plugin') as any;
335+
const { sentryWebpackPlugin } = loadModule<{ sentryWebpackPlugin: any }>('@sentry/webpack-plugin') ?? {};
336+
336337
if (sentryWebpackPlugin) {
337338
if (!userSentryOptions.sourcemaps?.disable) {
338339
// `hidden-source-map` produces the same sourcemaps as `source-map`, but doesn't include the `sourceMappingURL`

packages/utils/src/node.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ export function loadModule<T>(moduleName: string): T | undefined {
5252
// no-empty
5353
}
5454

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

6264
return mod;

0 commit comments

Comments
 (0)