Ts-node: 'rootDir' is expected to contain all source files

Created on 13 Feb 2017  路  5Comments  路  Source: TypeStrong/ts-node

I am facing issue with ngx-uploader. when I run tsc, it's working fine. but when I run npm start it is giving me below error
error TS6059: File 'node_modules/ngx-uploader/src/classes/index.ts' is not under 'rootDir' 'xxx/src'. 'rootDir' is expected to contain all source files.

tsconfig.json
{ "compilerOptions": { "target": "es5", "module": "commonjs", "moduleResolution": "node", "sourceMap": true, "rootDir": "src/", "outDir": "build", "emitDecoratorMetadata": true, "experimentalDecorators": true, "lib": [ "es2015", "dom" ], "noImplicitAny": true, "suppressImplicitAnyIndexErrors": true }, "exclude": [ "node_modules", "**/*.spec.ts", "bower_components", "build" ] }

needs more info

Most helpful comment

should exclude all source filesin tsconfig.json锛宔xample:

{
  "exclude": ["node_modules", "lib", "tests"]
}

here /tests contain ts source files.
see: https://github.com/Microsoft/TypeScript/issues/9858

All 5 comments

Can you share the commands you're running? Since ts-node is really just tsc in-memory, it seems there must be some other difference here. Why and how are you running .ts files from node_modules anyway?

Below is the package.json
{ "name": "tconsole", "version": "0.0.1", "private": true, "scripts": { "start": "tsc && concurrently \"tsc -w\" \"node server.js\" ", "e2e": "tsc && concurrently \"http-server -s\" \"protractor protractor.config.js\" --kill-others --success first", "lint": "tslint ./app/**/*.ts -t verbose", "lite": "lite-server", "pree2e": "webdriver-manager update", "test": "tsc && concurrently \"tsc -w\" \"karma start karma.conf.js\"", "test-once": "tsc && karma start karma.conf.js --single-run", "tsc": "tsc", "tsc:w": "tsc -w", "build": "tsc", "node-start": "node server.js" }, "dependencies": { "@angular/common": "~2.4.0", "@angular/compiler": "~2.4.0", "@angular/core": "~2.4.0", "@angular/forms": "~2.4.0", "@angular/http": "~2.4.0", "@angular/material": "^2.0.0-beta.1", "@angular/platform-browser": "~2.4.0", "@angular/platform-browser-dynamic": "~2.4.0", "@angular/router": "~3.4.0", "@vaadin/angular2-polymer": "^1.0.0", "angular-in-memory-web-api": "~0.2.4", "aws-sdk": "^2.12.0", "body-parser": "~1.15.1", "chalk": "^1.1.3", "connect-flash": "^0.1.1", "connect-mongo": "^1.3.2", "cookie-parser": "~1.4.3", "cookie-session": "^2.0.0-alpha.1", "core-js": "^2.4.1", "csurf": "^1.9.0", "debug": "~2.2.0", "ejs": "^2.5.2", "express": "~4.13.4", "express-session": "^1.14.1", "formidable": "^1.1.1", "gulp-copy": "^1.0.0", "kontainer-di": "~0.9.9", "mongoose": "^4.6.0", "mongoose-user": "0.0.1", "ngx-uploader": "^2.1.6", "node-uuid": "^1.4.7", "passport": "^0.3.2", "passport-local": "^1.0.0", "rxjs": "5.0.1", "serve-favicon": "~2.3.0", "systemjs": "0.19.40", "winston": "^2.2.0", "zone.js": "^0.7.4" }, "devDependencies": { "@types/jasmine": "^2.5.36", "@types/node": "^6.0.46", "browser-sync": "^2.18.7", "canonical-path": "0.0.2", "concurrently": "^3.1.0", "gulp": "^3.9.1", "gulp-watch": "^4.3.11", "http-server": "^0.9.0", "jasmine-core": "~2.4.1", "karma": "^1.3.0", "karma-chrome-launcher": "^2.0.0", "karma-cli": "^1.0.1", "karma-jasmine": "^1.0.2", "karma-jasmine-html-reporter": "^0.2.2", "lite-server": "^2.2.2", "lodash": "^4.16.4", "morgan": "~1.7.0", "protractor": "~4.0.14", "rimraf": "^2.5.4", "tslint": "^3.15.1", "typescript": "~2.0.10" } }
This .ts file came with ngx-uploader and don't know why it's being compile. tried to exclude it but didn't work.

There's no code in there using ts-node. The error is from tsc. The problem is your dependency - your depending on a TypeScript file outside of src/ and need to fix that.

How to fix this issue if it is node_modules package ?

should exclude all source filesin tsconfig.json锛宔xample:

{
  "exclude": ["node_modules", "lib", "tests"]
}

here /tests contain ts source files.
see: https://github.com/Microsoft/TypeScript/issues/9858

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mattdell picture mattdell  路  4Comments

aj-r picture aj-r  路  3Comments

huan picture huan  路  3Comments

watzon picture watzon  路  3Comments

joshua-tj picture joshua-tj  路  3Comments