Typescript: error TS6059: File 'xxx/node_modules/typescript/Gulpfile.ts' is not under 'rootDir'

Created on 5 Sep 2016  路  5Comments  路  Source: microsoft/TypeScript

TypeScript Version: nightly (2.1.0-dev.20160905)

Code
I'm not using gulp or other external tools

(the first line is not related to this issue)

[root /data/nodejs/json-env-cli]# tsc -w
error TS2688: Cannot find type definition file for './global.d.ts'.

error TS6059: File '/data/nodejs/json-env-cli/node_modules/typescript/Gulpfile.ts' is not under 'rootDir' '/data/nodejs/json-env-cli/src'. 'rootDir' is expected to contain all source files.

7:56:38 PM - Compilation complete. Watching for file changes.
{
    "compileOnSave": true,
    "compilerOptions": {
        "module": "commonjs",
        "target": "es6",
        "moduleResolution": "node",
        "noEmitOnError": false,
        "noImplicitThis": true,
        "noImplicitAny": false,
        "removeComments": false,
        "preserveConstEnums": true,
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "forceConsistentCasingInFileNames": true,
        "isolatedModules": false,
        "pretty": true,
        "sourceMap": true,
        "baseUrl": "./",
        "typeRoots": ["typings"],
        "types": ["./global.d.ts"],
        "lib": ["es6"],
        "outDir": "./dist",
        "rootDir": "./src"
    },
    "exclude": ["global.d.ts"]
}

Expected behavior:
ts file in "src" will compile to "dist", without error

Actual behavior:
files compiled but print an error

Question

Most helpful comment

I finally fixed this by:

move "tsconfig.json" to "src"
change content to:

{
    "compileOnSave": true,
    "compilerOptions": {
        "module": "commonjs",
        "target": "es6",
        "lib": ["es6"],
        "moduleResolution": "node",
        "noEmitOnError": false,
        "noImplicitThis": true,
        "noImplicitAny": false,
        "removeComments": false,
        "preserveConstEnums": true,
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "forceConsistentCasingInFileNames": true,
        "isolatedModules": false,
        "pretty": true,
        "sourceMap": true,
        "baseUrl": "./",
        "typeRoots": [],
        "types": [],
        "outDir": "../dist",
        "rootDir": "./"
    },
    "exclude": ["node_module", "./dist", "global.d.ts"]
}

and set script.start in package.json = tsc -w -p src, scripts.build = tsc -p src

now content of src will 1 on 1 map to dist

All 5 comments

I am getting this issue also

error TS6059: File '/Users/XXX/projects/syncrow/src/fs_helpers/read_tree.ts' is not under 'rootDir' 'src'. 'rootDir' is expected to contain all source files.
error TS6059: File '/Users/XXX/projects/syncrow/src/utils/test_utils.ts' is not under 'rootDir' 'src'. 'rootDir' is expected to contain all source files.

[email protected]
[email protected]
macOS

add node_modules to your exclude list.

if no exclude is specified one, the compiler excludes node_modules, bower_components, <outDir>.

so your exclude should be ["node_module", "./dist", "global.d.ts"]

@jan-osch, i am not sure what is going on in your case. it is either the same issue or a different one, can not just tell from the error messages.

@mhegazy no effect. exclude: ["node_module", "./dist", "global.d.ts"] still report that error.

( by the way, my src/dist file struct )

/data/nodejs/json-env-cli
   + dist/
         + src/
               - index.js
         + node_modules/
               + typescript
                     - Gulpfile.js
                     - Gulpfile.js.map
    + src/
         - index.ts

I finally fixed this by:

move "tsconfig.json" to "src"
change content to:

{
    "compileOnSave": true,
    "compilerOptions": {
        "module": "commonjs",
        "target": "es6",
        "lib": ["es6"],
        "moduleResolution": "node",
        "noEmitOnError": false,
        "noImplicitThis": true,
        "noImplicitAny": false,
        "removeComments": false,
        "preserveConstEnums": true,
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "forceConsistentCasingInFileNames": true,
        "isolatedModules": false,
        "pretty": true,
        "sourceMap": true,
        "baseUrl": "./",
        "typeRoots": [],
        "types": [],
        "outDir": "../dist",
        "rootDir": "./"
    },
    "exclude": ["node_module", "./dist", "global.d.ts"]
}

and set script.start in package.json = tsc -w -p src, scripts.build = tsc -p src

now content of src will 1 on 1 map to dist

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MartynasZilinskas picture MartynasZilinskas  路  3Comments

jbondc picture jbondc  路  3Comments

DanielRosenwasser picture DanielRosenwasser  路  3Comments

siddjain picture siddjain  路  3Comments

bgrieder picture bgrieder  路  3Comments