-
-
Notifications
You must be signed in to change notification settings - Fork 434
Description
Bug Report
Problem
When using ts-loader with TypeScript 6.0, builds fail with TS5011 errors:
TS5011: The common source directory of 'tsconfig.json' is './src/connect'.
The 'rootDir' setting must be explicitly set to this or another path to adjust
your output's file layout.
This happens even when rootDir is correctly configured in tsconfig.json.
Root Cause
In dist/index.js line 419, the getTranspilationEmit function explicitly strips rootDir when calling transpileModule():
const { outputText, sourceMapText, diagnostics } = instance.compiler.transpileModule(contents, {
compilerOptions: { ...instance.compilerOptions, rootDir: undefined },
// ...
});In TypeScript 5.x this was harmless — the compiler silently inferred rootDir from the common source directory. In TypeScript 6.0, this inference was removed and rootDir must be explicitly set. Setting it to undefined now triggers TS5011.
Suggested Fix
Remove the rootDir: undefined override so the tsconfig's rootDir flows through:
compilerOptions: { ...instance.compilerOptions },Or, if there was a reason rootDir was originally stripped (to avoid output path computation in transpile-only mode), consider omitting it only when rootDir isn't explicitly configured.
Workaround
Patch ts-loader to remove the rootDir: undefined override. With yarn:
yarn patch ts-loader
# Edit dist/index.js line 419: remove `rootDir: undefined`
yarn patch-commit -s <patch-dir>
Environment
- ts-loader: 9.5.2 and 9.5.4 (both affected)
- TypeScript: 6.0.2
- webpack: 5.x
Related
- ts-loader forces 'isolatedModules' enabled when transpileOnly: true #1645 (similar pattern — ts-loader overriding compilerOptions in transpileOnly mode)