For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /configure/app/server/tsconfig-path.md.

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, the api/ directory)
  • Custom server compilation (the server/ directory, plus shared/ compiled with it)
  • Running server source directly at dev time, such as SSR and .ts files under config/

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:

  1. Explicit: server.tsconfigPath (resolved relative to appDirectory; absolute paths are supported).
  2. Convention: <appDirectory>/tsconfig.server.json, used automatically when it exists.
  3. 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:

ConditionBehavior
The effective module (after resolving extends) is an ES module value (es2015 / es6 / es2020 / es2022 / esnext / preserve, case-insensitive) and package.json#type is not moduleThe server code is compiled with module: CommonJS, as with the previous base preset: import() becomes require() and extensionless specifiers keep working. moduleResolution is node10 before TypeScript 6 and bundler from TypeScript 6 on. Nothing is reported
module is commonjs / node16 / nodenext / ...Not rewritten
package.json#type is moduleNot rewritten (the output is ESM; the framework appends .js to relative imports)

moduleResolution is rewritten together with module, because TypeScript 5 rejects bundler with CommonJS (TS5095) and TypeScript 7 removes node10.

Keep one main tsconfig.json (editor, Rspack aliases, type-check) and add a tsconfig.server.json that only changes module options:

tsconfig.json
{
  "extends": "@modern-js/tsconfig/base",
  "compilerOptions": {
    "noEmit": true,
    "isolatedModules": true,
    "moduleDetection": "force",
    "noEmitOnError": true,
    "types": ["@modern-js/app-tools/types"],
    "paths": {
      "@/*": ["./src/*"],
      "@shared/*": ["./shared/*"],
      "@api/*": ["./api/lambda/*"]
    }
  },
  "include": ["src", "shared", "config", "api", "server", "modern.config.ts"]
}
tsconfig.server.json
{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "noEmit": false,
    "declaration": false
  },
  "include": ["api", "server", "shared"]
}

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:

modern.config.ts
export default defineConfig({
  server: {
    tsconfigPath: './config/tsconfig.node.json',
  },
});

Notes

  • paths must stay in tsconfig.json. TypeScript merges compilerOptions key by key across extends but replaces paths wholesale, so declaring paths in tsconfig.server.json drops every alias from the main config. The framework reads aliases through the whole extends chain, so the server config only needs to inherit them.
  • include in tsconfig.server.json only needs to list the server-side directories.
  • Keeping extends a single string in tsconfig.server.json keeps the file readable for tools still on ts-node 10.
  • The tsconfig "ts-node" section keeps working: its compilerOptions override the file, and modules in require are loaded before the server code.
  • Without typescript installed, 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 previous commonjs + node config) instead, but TypeScript 6 reports those options as deprecated.