Skip to content

[CLI] Exit non-zero with a clear message when next typegen fails#94241

Merged
gaojude merged 2 commits into
canaryfrom
gaojude/typegen-fail-loudly
May 30, 2026
Merged

[CLI] Exit non-zero with a clear message when next typegen fails#94241
gaojude merged 2 commits into
canaryfrom
gaojude/typegen-fail-loudly

Conversation

@gaojude
Copy link
Copy Markdown
Contributor

@gaojude gaojude commented May 29, 2026

The typegen command chained nextTypegen(...).then(() => process.exit(0)) with no rejection handler. When next.config throws during loadConfig, the rejection is orphaned by the synchronous program.parse and then absorbed by Next's unhandledRejection filter, so the process exits 0 having written no route types. A later tsc then reports Cannot find name 'PageProps'/'LayoutProps' (and missing *.png modules) with nothing tying it back to typegen. Add a .catch that prints an actionable message about the missing route types and process.exit(1), so next typegen && tsc halts on failure. Includes an e2e test whose fixture config throws and asserts a non-zero exit with the diagnostic.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 29, 2026

Stats cancelled

Commit: 86fe01c
View workflow run

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 29, 2026

Tests Passed

Commit: 86fe01c

@gaojude gaojude marked this pull request as ready for review May 29, 2026 18:46
@gaojude gaojude requested a review from lukesandberg May 29, 2026 19:55
Comment thread packages/next/src/bin/next.ts Outdated
Comment on lines +532 to +536
'\n> Failed to generate route types. The global `PageProps` and ' +
'`LayoutProps` helpers and other generated route types were not ' +
"written, which can surface as `Cannot find name 'PageProps'` " +
'errors during type checking. This is often caused by ' +
'`next.config` failing to load. Original error:\n'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this seems a little wordy, do we really need to say that the types were not written? (actually they may have been written if the failure was late enough)

A simple: Unexpected error while generating route types, Original error:\n is probably enough.

@gaojude gaojude enabled auto-merge (squash) May 30, 2026 21:43
@gaojude gaojude merged commit acb74eb into canary May 30, 2026
295 of 298 checks passed
@gaojude gaojude deleted the gaojude/typegen-fail-loudly branch May 30, 2026 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants