Ts-node: Issue with ts-node + Mocha: 'rootDir' is expected to contain all source files

Created on 3 Nov 2016  Â·  5Comments  Â·  Source: TypeStrong/ts-node

I am trying to run my tests with mocha and ts-node compiler.

I have a src folder with my code and test with a few tests.

This is my tsconfig.json:

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "ES6",
        "outDir": "dist",
        "rootDir": "src",
        "sourceMap": true
    },
    "exclude": [
        "node_modules"
    ]
}

I am running the following command: mocha --compilers ts:ts-node/register test/**.ts
And when i do, i get this:

TSError: ⨯ Unable to compile TypeScript...
is not under 'rootDir'...
'rootDir' is expected to contain all source files. (6059)

Is there any easy way to circumvent this issue without having all the source code and the tests under the src folder?

Most helpful comment

I solved this by changing rootDir to rootDirs: ["src","test"], and it worked.

All 5 comments

I solved this by changing rootDir to rootDirs: ["src","test"], and it worked.

We could probably override rootDirs, but I'm not sure if that would introduce any odd side-effects in terms of TypeScript compilation. If someone knows, let me know. /cc @mhegazy

Having rootDir and rootDirs is silly but it is not your fault.

why are you using rootDirs? I am not sure i see how this is relevant to the error you saw. here is more information about what rootDirs mean:http://www.typescriptlang.org/docs/handbook/module-resolution.html#virtual-directories-with-rootdirs

Any reason why switching from "rootDir" to "rootDirs" worked? I had the same issue with webpack.config.ts until I switched.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dakom picture dakom  Â·  3Comments

JoseLion picture JoseLion  Â·  3Comments

cevek picture cevek  Â·  4Comments

sanex3339 picture sanex3339  Â·  4Comments

nehalist picture nehalist  Â·  3Comments