Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing module.compiled trace file and unhandledRejection in ensurePage #55553

Merged
merged 4 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 8 additions & 5 deletions packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2269,12 +2269,13 @@ export default async function build(
const moduleTypes = ['app-page', 'pages']

for (const type of moduleTypes) {
const modulePath = require.resolve(
`next/dist/server/future/route-modules/${type}/module.compiled`
)
const relativeModulePath = path.relative(root, modulePath)

const contextDir = path.join(
path.dirname(
require.resolve(
`next/dist/server/future/route-modules/${type}/module`
)
),
path.dirname(modulePath),
'vendored',
'contexts'
)
Expand All @@ -2287,6 +2288,8 @@ export default async function build(
addToTracedFiles(root, itemPath, tracedFiles)
addToTracedFiles(root, itemPath, minimalTracedFiles)
}
addToTracedFiles(root, relativeModulePath, tracedFiles)
addToTracedFiles(root, relativeModulePath, minimalTracedFiles)
}

await Promise.all([
Expand Down
16 changes: 12 additions & 4 deletions packages/next/src/server/dev/on-demand-entry-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -726,9 +726,12 @@ export function onDemandEntryHandler({
const isInsideAppDir =
!!appDir && pagePathData.absolutePagePath.startsWith(appDir)

if (typeof isApp === 'boolean' && !(isApp === isInsideAppDir)) {
if (typeof isApp === 'boolean' && isApp !== isInsideAppDir) {
Error.stackTraceLimit = 15
throw new Error(
'Ensure bailed, found path does not match ensure type (pages/app)'
`Ensure bailed, found path "${
pagePathData.page
}" does not match ensure type (${isApp ? 'app' : 'pages'})`
)
}

Expand Down Expand Up @@ -912,7 +915,7 @@ export function onDemandEntryHandler({
match?: RouteMatch
isApp?: boolean
}) {
if (curEnsurePage.has(page)) {
if (typeof isApp !== 'boolean' && curEnsurePage.has(page)) {
return curEnsurePage.get(page)
}
const promise = ensurePageImpl({
Expand All @@ -921,7 +924,12 @@ export function onDemandEntryHandler({
appPaths,
match,
isApp,
}).finally(() => {
})

if (typeof isApp === 'boolean') {
return promise
}
promise.finally(() => {
curEnsurePage.delete(page)
})
curEnsurePage.set(page, promise)
Expand Down