Skip to content

fix: Cannot read properties of undefined (reading '_isAppDir') #53818

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions packages/next/src/export/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,9 +547,10 @@ export default async function exportApp(

const filteredPaths = exportPaths.filter(
// Remove API routes
(route) =>
(exportPathMap[route] as any)._isAppDir ||
!isAPIRoute(exportPathMap[route].page)
(route) => {
const { _isAppDir, page } = exportPathMap[route] || {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we narrow in on the case this is empty? It shouldn't be as that seems to be leading to a more lower down issue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed but we don't have repro steps so its unclear at which point the entry is missing

Maybe @ovflowd can create a branch with the failing code again.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an easy way I can test this commit of Next.js locally?

return _isAppDir || !isAPIRoute(page)
}
)

if (filteredPaths.length !== exportPaths.length) {
Expand Down Expand Up @@ -699,7 +700,9 @@ export default async function exportApp(

return pageExportSpan.traceAsyncFn(async () => {
const pathMap = exportPathMap[path]
const exportPageOrApp = pathMap._isAppDir ? exportAppPage : exportPage
const exportPageOrApp = pathMap?._isAppDir
? exportAppPage
: exportPage
if (!exportPageOrApp) {
throw new Error(
'invariant: Undefined export worker for app dir, this is a bug in Next.js.'
Expand Down
4 changes: 2 additions & 2 deletions packages/next/src/export/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ export default async function exportPage({
const { query: originalQuery = {} } = pathMap
const { page } = pathMap
const pathname = normalizeAppPath(page)
const isAppDir = (pathMap as any)._isAppDir
const isDynamicError = (pathMap as any)._isDynamicError
const isAppDir = Boolean(pathMap._isAppDir)
const isDynamicError = pathMap._isDynamicError
const filePath = normalizePagePath(path)
const isDynamic = isDynamicRoute(page)
const ampPath = `${filePath}.amp`
Expand Down