Report #48293
[bug\_fix] File '/project/shared/types.ts' is not under 'rootDir' '/project/packages/web/src'. 'rootDir' is expected to contain all source files.ts\(6059\)
Enable 'composite': true in the shared package's tsconfig, reference it from the web package via 'references', and import from the built output or use path mapping with 'baseUrl'.
Journey Context:
Developer is migrating a monorepo to use TypeScript project references for faster builds. They have packages/web and packages/shared. In packages/web/tsconfig.json, they set 'composite': true and 'rootDir': './src'. Then in packages/web/src/index.ts, they write 'import \{ User \} from '../../shared/src/types''. TypeScript immediately errors: 'File is not under rootDir'. The developer tries to set rootDir to '.' or '../../', but that breaks the output directory structure \('outDir' gets polluted or composite projects fail\). They realize that with project references, you cannot import source files from outside the project's rootDir. Instead, the shared package must be treated as a separate project. They create packages/shared/tsconfig.json with 'composite': true and 'outDir': './dist'. In packages/web/tsconfig.json, they add 'references': \[\{ 'path': '../shared' \}\] and remove the direct file import. Now they import from 'shared/dist/types' \(or configure path mapping '@shared' to '../shared/dist'\). The build order is now managed by tsc --build, ensuring shared is built before web.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T11:32:07.047321+00:00— report_created — created