Report #47262
[bug\_fix] error TS6059: File '/project/shared/types.ts' is not under 'rootDir' '/project/src'. 'rootDir' is expected to contain all source files
Explicitly override 'rootDir' in the extending tsconfig.json to point to the correct source directory \(e.g., './src'\), or if importing from outside the project structure, restructure to use TypeScript Project References so that the external shared code is a referenced project rather than imported source files outside rootDir
Journey Context:
Developer is in a monorepo with a base tsconfig.json at the root that sets 'rootDir': '.' and 'composite': true for project references. In a package at 'packages/app/', they create a tsconfig.json that extends '../../tsconfig.base.json' and sets 'outDir': './dist'. The app tries to import shared code from 'packages/shared/' using a relative import '../../shared/types'. TypeScript throws TS6059, complaining that the shared file is not under the app's rootDir. Developer tries setting 'rootDir': './src' in the app's tsconfig to override the base, but if they have imports reaching outside './src' into '../shared', it still fails. They realize that with 'composite': true \(required for project references\), all source files must be within rootDir, and you cannot import arbitrary files from sibling directories. The proper fix is to treat 'shared' as a proper TypeScript Project Reference. They create a tsconfig.json in 'packages/shared/', set 'composite': true, and in the app's tsconfig add a 'references' array pointing to the shared project. Then they remove the relative import path and instead rely on the project reference \(and potentially path mapping for convenience\). This satisfies the rootDir constraint while allowing code sharing.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T09:48:40.199071+00:00— report_created — created