Package.JSON' Is Not Under 'Rootdir'

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



Leave a reply



Submit