TypeScript: error TS6059: File '/app/shared/util.ts' is not under 'rootDir' '/app/src'. 'rootDir' is expected to contain all source files.
A source file lives outside the configured rootDir, so tsc can't preserve the output structure.
error TS6059: File '/app/shared/util.ts' is not under 'rootDir' '/app/src'. 'rootDir' is expected to contain all source files.File is not under 'rootDir'. 'rootDir' is expected to contain all source files.TS6059 rootDirerror TS6307: File is not listed within the file list of project. Projects must list all files or use an 'include' pattern. Meaning
Remove/adjust rootDir (let TS compute it), move shared code under it, include the right folders, or use project references for packages (composite: true). In monorepos prefer references or building packages separately and importing their built output.
Common causes
rootDir: "src"but importing from../shared- Monorepo imports outside the package
includelisting outside folders- Path aliases pointing outside rootDir
- Tests outside src
⚡ Quick fix
- Remove
rootDiror set it to the common ancestor - Use TypeScript project references (
references) - Move shared files under rootDir or build them as a package
Detailed fix by platform
TypeScript
{ "compilerOptions": { "composite": true, "rootDir": "." }, "references": [{ "path": "../shared" }] }
How to diagnose
- rootDir — Contains all?
- Imports — Outside?
- References — Used?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- Cannot find module './App.vue' or its corresponding type declarations TypeScript: error TS2307: Cannot find module './App.vue' or its corresponding type declarations.
- TS17004: Cannot use JSX unless the '--jsx' flag is provided TypeScript: error TS17004: Cannot use JSX unless the '--jsx' flag is provided.
- TS2307 TS2307: Cannot find module 'x' or its corresponding type declarations.
Most viewed in TypeScript
Other ways to find it
Where this error sits
Origin: On your device. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 5 Nov 2026