Skip to content

Commit

Permalink
resolve external with module type
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Sep 24, 2022
1 parent 243085c commit cbb7e73
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions packages/next/build/webpack-config.ts
Expand Up @@ -999,24 +999,25 @@ export default async function getBaseWebpackConfig(
return `commonjs next/dist/lib/import-next-warning`
}

const resolveWithReactServerCondition =
layer === WEBPACK_LAYERS.server
? getResolve({
// If React is aliased to another channel during Next.js' local development,
// we need to provide that alias to webpack's resolver.
alias: process.env.__NEXT_REACT_CHANNEL
? {
react: `react-${process.env.__NEXT_REACT_CHANNEL}`,
'react-dom': `react-dom-${process.env.__NEXT_REACT_CHANNEL}`,
}
: false,
// Prefer to resolve react-server condition first, fallback to node condition
conditionNames: ['react-server'],
})
: null

// Special internal modules that must be bundled for Server Components.
if (layer === WEBPACK_LAYERS.server) {
if (!isLocal && /^react(?:$|\/)/.test(request)) {
const resolveWithReactServerCondition =
layer === WEBPACK_LAYERS.server
? getResolve({
// If React is aliased to another channel during Next.js' local development,
// we need to provide that alias to webpack's resolver.
alias: process.env.__NEXT_REACT_CHANNEL
? {
react: `react-${process.env.__NEXT_REACT_CHANNEL}`,
'react-dom': `react-dom-${process.env.__NEXT_REACT_CHANNEL}`,
}
: false,
// Prefer to resolve react-server condition first, fallback to node condition
conditionNames: ['react-server', 'node', 'require'],
})
: null
const [resolved] = await resolveWithReactServerCondition!(
context,
request
Expand Down Expand Up @@ -1157,10 +1158,9 @@ export default async function getBaseWebpackConfig(
context,
request
)
return resolved
return `${externalType} ${resolved}`
} catch (err) {
// The `react-server` condition is not matched, fallback.
return
}
}

Expand Down

0 comments on commit cbb7e73

Please sign in to comment.