Skip to content

Commit

Permalink
Fix next build error
Browse files Browse the repository at this point in the history
  • Loading branch information
timneutkens committed Aug 15, 2022
1 parent 5844f41 commit 69be2de
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 24 deletions.
2 changes: 1 addition & 1 deletion packages/next/build/webpack/loaders/next-app-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async function createTreeCodeFromPath({
// First item in the list is the page which can't have layouts by itself
if (i === segments.length - 1) {
// Use '' for segment as it's the page. There can't be a segment called '' so this is the safest way to add it.
tree = `['', {}, {page: () => require('${pagePath}')}]`
tree = `['', {}, {page: () => require('${await resolve(pagePath)}')}]`
continue
}

Expand Down
31 changes: 8 additions & 23 deletions packages/next/build/webpack/plugins/flight-client-entry-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,17 @@ export class FlightClientEntryPlugin {
entryModule
)) {
const layoutOrPageDependency = connection.dependency
const layoutOrPageRequest = connection.dependency.request

const [clientComponentImports, cssImports] =
this.collectClientComponentsAndCSSForDependency({
context: compiler.context,
layoutOrPageRequest,
compilation,
dependency: layoutOrPageDependency,
})

Object.assign(flightCSSManifest, cssImports)

const layoutOrPageRequest = connection.dependency.request
const isAbsoluteRequest = layoutOrPageRequest[0] === '/'

// Next.js internals are put into a separate entry.
Expand Down Expand Up @@ -180,11 +180,11 @@ export class FlightClientEntryPlugin {
}

collectClientComponentsAndCSSForDependency({
context,
layoutOrPageRequest,
compilation,
dependency,
}: {
context: string
layoutOrPageRequest: string
compilation: any
dependency: any /* Dependency */
}): [ClientComponentImports, CssImports] {
Expand Down Expand Up @@ -223,11 +223,11 @@ export class FlightClientEntryPlugin {
if (!visitedBySegment[segmentPath]) {
visitedBySegment[segmentPath] = new Set()
}
if (!modRequest || visitedBySegment[segmentPath].has(modRequest)) return
if (!modRequest || visitedBySegment[segmentPath].has(modRequest)) {
return
}
visitedBySegment[segmentPath].add(modRequest)

const isLayoutOrPage =
/\/(layout|page)(\.server|\.client)?\.(js|ts)x?$/.test(modRequest)
const isCSS = regexCSS.test(modRequest)
const isClientComponent = clientComponentRegex.test(modRequest)

Expand All @@ -242,21 +242,6 @@ export class FlightClientEntryPlugin {
return
}

if (isLayoutOrPage) {
segmentPath = path
.relative(path.join(context, 'app'), path.dirname(modRequest))
.replace(/\\/g, '/')

if (segmentPath !== '') {
segmentPath = '/' + segmentPath
}

// If it's a page, add an extra '/' to the segments
if (/\/(page)(\.server|\.client)?\.(js|ts)x?$/.test(modRequest)) {
segmentPath += '/'
}
}

compilation.moduleGraph
.getOutgoingConnections(mod)
.forEach((connection: any) => {
Expand All @@ -265,7 +250,7 @@ export class FlightClientEntryPlugin {
}

// Traverse the module graph to find all client components.
filterClientComponents(dependency, '')
filterClientComponents(dependency, layoutOrPageRequest)

return [clientComponentImports, serverCSSImports]
}
Expand Down

0 comments on commit 69be2de

Please sign in to comment.