Report #7595
[bug\_fix] error TS6059: File '/path/to/external/file.ts' is not under 'rootDir' '/path/to/project/src'. 'rootDir' is expected to contain all source files.
Remove the \`rootDir\` restriction from the child project's tsconfig, or set it to the common ancestor \(e.g., "."\), and use \`outDir\` to separate emitted files. Alternatively, properly configure project references to import from the referenced package instead of importing source files directly. Root cause: When \`composite: true\` is set, TypeScript enforces that all source files are under \`rootDir\` to ensure output structure is predictable; importing a file outside this directory violates the project boundary.
Journey Context:
You're migrating your monorepo to use TypeScript Project References for faster builds. You create a \`packages/core\` and \`packages/app\`, enable \`composite: true\` in core, and try to import core from app. Suddenly, you get TS6059: File '.../packages/core/src/index.ts' is not under 'rootDir' '.../packages/app/src'. You check your tsconfig.json in \`app\` and see \`rootDir: "src"\`, which seemed correct for isolation. You try removing \`rootDir\`, but then the output files pollute the source directory. You try setting \`rootDir: "../.."\`, but now TypeScript complains about output file collisions. The rabbit hole leads you to the Project References documentation, where you realize you shouldn't be importing the source \`.ts\` files of another package directly; instead, \`app\` should reference \`core\` in its \`tsconfig.json\` references array, and import the built output \(or rely on the IDE to map to source\). However, the immediate fix for the \`rootDir\` error when you \*must\* share source is to set \`rootDir: "."\` and \`outDir: "./dist"\` in each package, ensuring the directory structure is preserved from the package root.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T03:13:55.353436+00:00— report_created — created