Skip to content

Commit

Permalink
fix(nextjs): Resolve path for dynamic webpack import (#13751)
Browse files Browse the repository at this point in the history
  • Loading branch information
chargome authored Nov 5, 2024
1 parent e45566d commit ff18dfd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion packages/nextjs/src/config/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,8 @@ export function constructWebpackConfigFunction(
// Symbolication for dev-mode errors is done elsewhere.
if (!isDev) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const { sentryWebpackPlugin } = loadModule('@sentry/webpack-plugin') as any;
const { sentryWebpackPlugin } = loadModule<{ sentryWebpackPlugin: any }>('@sentry/webpack-plugin') ?? {};

if (sentryWebpackPlugin) {
if (!userSentryOptions.sourcemaps?.disable) {
// `hidden-source-map` produces the same sourcemaps as `source-map`, but doesn't include the `sourceMappingURL`
Expand Down
12 changes: 7 additions & 5 deletions packages/utils/src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ export function loadModule<T>(moduleName: string): T | undefined {
// no-empty
}

try {
const { cwd } = dynamicRequire(module, 'process');
mod = dynamicRequire(module, `${cwd()}/node_modules/${moduleName}`) as T;
} catch (e) {
// no-empty
if (!mod) {
try {
const { cwd } = dynamicRequire(module, 'process');
mod = dynamicRequire(module, `${cwd()}/node_modules/${moduleName}`) as T;
} catch (e) {
// no-empty
}
}

return mod;
Expand Down

0 comments on commit ff18dfd

Please sign in to comment.