Skip to content

Commit

Permalink
map middleware and instrumentation module path to rsc
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Sep 5, 2024
1 parent a2fc6ac commit 0c22941
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/next/src/build/create-compiler-aliases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type { NextConfigComplete } from '../server/config-shared'
import { defaultOverrides } from '../server/require-hook'
import { NEXT_PROJECT_ROOT, hasExternalOtelApiPackage } from './webpack-config'
import { WEBPACK_LAYERS } from '../lib/constants'
import { isWebpackServerOnlyLayer } from './utils'

interface CompilerAliases {
[alias: string]: string | string[]
Expand Down Expand Up @@ -248,6 +249,14 @@ export function createRSCAliases(
reactProductionProfiling: boolean
}
): CompilerAliases {
const isServerOnlyLayer = isWebpackServerOnlyLayer(layer)
// For middleware, instrumentation layers, treat them as rsc layer.
// Since we only built the runtime package for rsc, convert everything to rsc
// to ensure the runtime modules path existed.
if (isServerOnlyLayer) {
layer = WEBPACK_LAYERS.reactServerComponents
}

let alias: Record<string, string> = {
react$: `next/dist/compiled/react${bundledReactChannel}`,
'react-dom$': `next/dist/compiled/react-dom${bundledReactChannel}`,
Expand Down

0 comments on commit 0c22941

Please sign in to comment.