error TS6059: File is not under 'rootDir' .. 'rootDir' is expected to contain all source files
What is rootDir
?
rootDir
is set to a root folder, that contains all your source files. If not specified, TS will automatically choose a suitable parent folder of all inputs. rootDir
also determines the output directory.
What does the error mean?
My guess is you have an import
statement for logging.ts
somewhere in notifier-server
:
import {logger} from "@teros-cli/logging" // or similar
Then logging.ts
module will be automatically included by the compiler, regardless of include
and exclude
options in tsconfig.json
. One way to check all included files is tsc --listFiles
.
A tsconfig.json
file outside notifier-server
doesn't help here. The compiler picks up exactly one config per tsc
compilation and optionally pulls inherited configs. If it cannot find one in notifier-server
project root (where you started tsc
), only then the compiler searches upwards the parent directory chain, until a config is found.
Possible solutions
One fix is to just remove "rootDir": "src"
from compiler options, so it gets set automatically. Caution: rootDir
will then consider both projects as inputs!
Alternative: You can add a separate logging.ts
module contained in notifier-server/src
project and drop the external import
.
Hope, that helps!
File is not under 'rootDir' in Cypress tsconfig.json
Your issue is coming from the fact that the entirety of the cypress
folder is not contained under src
. When setting the cypress/tsconfig.json
file, you can override the rootDir
property set in the parent tsconfig.json
file.
Try setting that field to the cypress directory.
...
"compilerOptions: {
"rootDir": "./"
...
},
...
^ The above may work, since the tsconfig
is within the cypress
directory.
rootDir' is expected to contain all source files in monorepo
In the end the fix was to remove any reference to rootDir from all files other than the tsconfig.json
file in the root (which I left as .
).
unreferenced .ts file in project's root is not under root dir
As you can see in the TypeScript docs, rootDir
is only used for the directory structure when using outDir
. What you need is to tell TypeScript which files to include (or exclude) by using the include
or exclude
config option respectively.
In your case you could either add include: ['src/**/*']
to only use files in your source directoy, or exclude your scripts with exclude: ['utilities/**/*']
(replace 'utilities' by your scripts folder).
An example tsconfig could then look like this:
{
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
// your compile options
},
"include": ["src/**/*"], // only include your src directory
"exclude": ["**/*.spec.ts"] // exclude tests and add scripts if you have any in "src/"
}
include
works like a whitelist. Only files that match any of the glob pattern here is included in your build. exclude
works like a blacklist. Files that match any of the glob pattern here will be excluded from your build (even if matched by include
).
Related Topics
Does Execcommand Saveas Work in Firefox
Referenceerror: Document Is Not Defined (In Plain JavaScript)
How to Convert from Hex to Ascii in JavaScript
When Should I Use a Semicolon After Curly Braces
Call JavaScript Function from Url/Address Bar
What Is the $$ (Double Dollar Sign) Used for in Angular
Fade in on Scroll Down, Fade Out on Scroll Up - Based on Element Position in Window
Es6 Modules Implementation, How to Load a JSON File
[Vue Warn]: Property or Method Is Not Defined on the Instance But Referenced During Render
Jquery's Live() Is Deprecated. What Do I Use Now
How to Scroll the Window Using Jquery $.Scrollto() Function
Dom Refresh on Long Running Function
Checking for Duplicate Strings in JavaScript Array
Unique Object Identifier in JavaScript
How to Populate the Options of a Select Element in JavaScript
How to Disable Right-Click Context-Menu in JavaScript
Google Maps Move Marker with Lat/Lng from Ajax Success Returned Data