TypeScript "TS6059: not under 'rootDir'" - Fix Project Refs in CI
A file you compile imports source from outside the configured rootDir. rootDir defines the root of the input set; reaching across to another package's src/ (common in monorepos) violates it, and tsc refuses with TS6059.
What this error means
Type-checking fails with error TS6059: '<file>' is not under 'rootDir' '<dir>'. 'rootDir' is expected to contain all source files. It names the cross-boundary file.
error TS6059: File '/repo/packages/shared/src/types.ts' is not under 'rootDir'
'/repo/packages/web/src'. 'rootDir' is expected to contain all source files.
The file is in the program because:
Imported via '../../shared/src/types' from file 'src/App.tsx'Common causes
Importing another package's source across rootDir
In a monorepo, web imports shared/src/... directly. Since shared is outside web's rootDir, tsc treats it as an out-of-root input and errors.
rootDir narrower than the actual input set
An explicit rootDir (e.g. src) that does not contain every file the program pulls in - including referenced files outside it - triggers TS6059.
How to fix it
Use project references for cross-package imports
Reference the other package as a built project and import its emitted types, not its raw source.
// packages/web/tsconfig.json
{
"compilerOptions": { "composite": true },
"references": [{ "path": "../shared" }]
}Widen rootDir or import the built package
- Either set
rootDirto a common ancestor that contains all inputs, - or import the dependency by its package name (resolved to its
dist/types), not a relative../../pkg/srcpath. - Avoid deep relative imports across package boundaries.
How to prevent it
- Use TypeScript project references in monorepos.
- Import sibling packages by name, not by relative paths into their
src. - Keep
rootDirconsistent with the real input set.