Skip to content

TS5011 errors with TypeScript 6.0: transpileModule called with rootDir: undefined #1678

Description

@julioz

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions