Repository navigation
fix(nextjs): export default from the generated next.config.ts - #705
Merged
leoortizz merged 2 commits intoNov 23, 2026
Merged
Conversation
The override for next.config.ts imports the original with an ES import but ended with `module.exports = config;`, so TypeScript saw no default export. Next.js type-checks the project during `next build` while the generated file is in place, and any project file that imports the config's default export failed with TS1192.
BiAksoy
requested review from
Yuangwang,
abhis3 and
annajowang
as code owners
November 3, 2026 15:53
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates the Next.js adapter to treat .ts files as ESM when overriding the Next.js configuration. It also updates the corresponding test suite to use export default config; instead of module.exports = config;. There are no review comments to address.
leoortizz
approved these changes
Nov 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For a project with
next.config.ts, the adapter replaces the config during the build with a generated file that imports the original with an ES import (overrides.ts L46-L51) but ends withmodule.exports = config;(L105). TypeScript treats that file as an ES module with no default export.next buildtype-checks the project while the generated file is in place, so any project file that doesimport nextConfig from "./next.config"(a test or a script reading the config, for example) fails the App Hosting build, even though the same project builds locally:That is from running the adapter's
dist/bin/build.json main against a minimal App Router app (<app>stands for the app's absolute path).// @ts-nocheckin the generated file does not help, because the error is reported in the importing file.The
.mjsand.mtsoverrides already end withexport default config;. This change adds.tsto that list, somodule.exportsis left only for.js, the one override that loads the original withrequire().Loading is unaffected. Next.js compiles
next.config.tswith SWC to CommonJS (v16.4.4, v15.5.28) and reads the result throughinteropDefault(config.ts, interop-default.ts:mod.default || mod), so either tail yields the same config object. I found no reason recorded formodule.exportsin the.tsbranch; it dates from #309, where the review discussion covers// @ts-nocheckbut not the export form.Testing
Unit: the existing TypeScript case (overrides.spec.ts L293-L320) now expects
export default config;. The.js,.mjsand.mtsexpectations are unchanged, and I compared the generated files from main and this branch for all four extensions: only.tsdiffers, in the last line.Functional: the
with-ts-configscenario builds and serves with the new override, so Next'sloadConfigandnext buildaccept it. It does not cover the import case, since the scenarios only write a config file. If you want that covered, I can add a unit case that type-checks a file importing the generated config with the TypeScript compiler API, or a scenario with an importing file (which needs a small change torun-local.ts).npm run build,npm run lint:quietand the package'snpm test(unit and functional) pass locally on Node 26.13.0. CI runs Node 18 and 22, which I did not run locally.I ran
dist/bin/build.jsagainst minimal App Router apps (TypeScript 5.9.3, React 19.3.1), before and after the change:next.config.tsexport defaultobject, plus a project file importing itmodule.exports =object (CommonJS in.ts)export default async functionIn every successful build the config's custom header was in
.next/routes-manifest.json,images.unoptimizedwastruein.next/required-server-files.json, and the originalnext.config.tswas restored afterwards.Not tested: an actual App Hosting rollout.
One related thing I left alone: with
next build --experimental-next-config-strip-types(Next 16.4.4), Node's native loader cannot resolve the generated file's extensionless./next.config.originalimport, so Next prints a warning and falls back to its SWC loader. That happens on main as well, and the build result is the same as without the flag.