server.tsconfigPath
- Type:
string - Default:
undefined(resolved automatically, see the precedence below)
Specifies the tsconfig file used by server-side TypeScript processes.
This option affects:
- BFF / API compilation (
@modern-js/plugin-bff, theapi/directory) - Custom server compilation (the
server/directory, plusshared/compiled with it) - Running server source directly at dev time, such as SSR and
.tsfiles underconfig/
At build time the framework runs the project's own tsc command with this tsconfig: one run type-checks api/, server/ and shared/ and emits them to the output directory (TypeScript 5, 6 and 7 all work), then the framework rewrites paths aliases in the output to relative paths. The framework no longer relies on the TypeScript JS API, and ts-node is not required; at dev time server code is loaded through the framework's SWC hooks.
Resolution precedence
The server tsconfig is resolved in this order; the first hit wins:
- Explicit:
server.tsconfigPath(resolved relative toappDirectory; absolute paths are supported). - Convention:
<appDirectory>/tsconfig.server.json, used automatically when it exists. - Fallback:
<appDirectory>/tsconfig.json.
In the first two cases the file is used as is, apart from always emitting (see below).
Fallback override rule
@modern-js/tsconfig/base is a bundler-oriented config (module: ESNext, moduleResolution: bundler). Compiled as is, it would emit ES modules that a CommonJS project cannot require().
So only when falling back to tsconfig.json, the framework checks:
moduleResolution is rewritten together with module, because TypeScript 5 rejects bundler with CommonJS (TS5095) and TypeScript 7 removes node10.
Recommended layout
Keep one main tsconfig.json (editor, Rspack aliases, type-check) and add a tsconfig.server.json that only changes module options:
The four compilerOptions override only those keys; everything else is inherited from tsconfig.json. @modern-js/tsconfig/server is published as the reference preset with the same four fields for tools that support extends arrays (tsc >= 5.0), and the recommended tsconfig.server.json inlines them so tools still on ts-node 10 (which does not support extends arrays) can read it.
Modern.js does not generate tsconfig.server.json. For an existing project, the migration Skill's script can write it (see Migrating an existing project); otherwise add it by hand with the content above.
When compiling api/, server/ and shared/, Modern.js always emits JavaScript (noEmit and emitDeclarationOnly are ignored; the server compile is an emit step). declaration is left to the config: when on, the same tsc run writes the .d.ts files a cross-project BFF relies on, with aliases rewritten to relative paths.
With tsconfig.server.json in place, server.tsconfigPath is not needed. Set it only when the file has a different name or location:
Notes
pathsmust stay intsconfig.json. TypeScript mergescompilerOptionskey by key acrossextendsbut replacespathswholesale, so declaringpathsintsconfig.server.jsondrops every alias from the main config. The framework reads aliases through the wholeextendschain, so the server config only needs to inherit them.includeintsconfig.server.jsononly needs to list the server-side directories.- Keeping
extendsa single string intsconfig.server.jsonkeeps the file readable for tools still on ts-node 10. - The tsconfig
"ts-node"section keeps working: itscompilerOptionsoverride the file, and modules inrequireare loaded before the server code. - Without
typescriptinstalled, the server code still compiles, but the type check is skipped with a notice. - Projects that do not want the new layout can extend
@modern-js/tsconfig/legacy(the previouscommonjs+nodeconfig) instead, but TypeScript 6 reports those options as deprecated.