next.js
cfc93493 - Render a code frame for build errors thrown collecting page data (#95270)

Commit
28 days ago
Render a code frame for build errors thrown collecting page data (#95270) Errors thrown while collecting page data, such as an empty `generateStaticParams` under Cache Components, printed a source-mapped stack in the build output but no code frame, unlike prerender errors from the export worker which show the offending source lines. The static worker exposes both `isPageStatic` and `exportPages`, but only `exportPages` called `installCodeFrameSupport`, so when `isPageStatic` ran the code-frame renderer was never registered and the frame was dropped even though the stack itself was already source-mapped. This installs the native bindings and code-frame support in the static worker entry (`build/worker.ts`) by wrapping the exposed `isPageStatic`, mirroring what `exportPages` already does. It is deliberately not done in `build/utils.ts`: that module is reachable from `next-server` through the dev server, so importing the code-frame installer there pulls the devtools renderer (`next-devtools/server/shared`) into the production server's file trace, which the `next-server-nft` test rightly rejects. The worker entry is only loaded by build workers, so the renderer stays out of the runtime server. Both installs are idempotent. With the renderer registered, a build error thrown from `generateStaticParams` now prints the same code frame as a prerender error, pointing at the offending line. The frame is only rendered when the source map carries source content, which happens under `--debug-prerender` (and otherwise `serverSourceMaps`), so normal minified production builds are unaffected. The `empty-generate-static-params` end-to-end test is updated to assert the code frame that now appears in the build error for both the literal and the computed empty array cases.
Author
Parents
Loading