diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index 31eeb0454263f..7c21ce7acbd9a 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -336,6 +336,17 @@ export default async function getBaseWebpackConfig( return callback() } + let baseRes + try { + baseRes = resolveRequest(request, dir) + } catch (err) {} + + // If the package, when required from the root, would be different from + // what the real resolution would use, then we cannot externalize it + if (baseRes !== res) { + return callback() + } + // Default pages have to be transpiled if ( !res.match(/next[/\\]dist[/\\]next-server[/\\]/) &&