Report #11242
[bug\_fix] File '.../shared/src/types.ts' is not under 'rootDir' '.../packages/a/src'. 'rootDir' is expected to contain all source files \(TS6059\)
Use TypeScript Project References: Mark the shared code directory as a composite project \(\`"composite": true\` in its tsconfig\), reference it from the consuming project's tsconfig via the \`references\` array, and import the shared code using the reference path or package name rather than relative file paths outside the rootDir.
Journey Context:
You are in a monorepo using TypeScript Project References for faster builds. \`packages/app\` needs to import a type from \`packages/shared\`. You write \`import \{ User \} from '../../shared/src/types';\`. TypeScript immediately throws TS6059. You check the \`tsconfig.json\` for \`packages/app\` and see \`"rootDir": "./src"\`. You think, "I'll just change rootDir to '.'." But then \`tsc\` starts outputting \`.js\` files all over the monorepo or the \`outDir\` structure breaks. You try to use \`paths\` mapping \`"@shared/\*": \["../shared/src/\*"\]\`, but the error persists because \`rootDir\` constraint is enforced strictly for composite projects. You realize that with \`composite: true\`, TypeScript forbids source files outside \`rootDir\` to ensure project boundaries are respected. The correct architecture is to treat \`shared\` as a separate project. You add a \`tsconfig.json\` in \`packages/shared\` with \`"composite": true, "declaration": true\`, then in \`packages/app/tsconfig.json\` you add \`"references": \[\{ "path": "../shared" \}\]\`. You change the import to \`from 'shared'\` \(using \`paths\` or package.json exports\). Now the compiler builds \`shared\` first, \`app\` second, respecting the boundaries.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T12:50:17.049497+00:00— report_created — created