Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gulp typescript tsconfig with Angular2

I have problem with excluding folders in my app. I'm using a gulp typescript for compilation and tsconfig file. Problem is with node_modules folder, which is still compiling.

Here is my gulpfile:

var tsProject = ts.createProject('tsconfig.json', { typescript: require('typescript') });

gulp.task('tscompile', function () {
var tsResult = tsProject.src("./angular/**/*.ts") // instead of gulp.src(...)
    .pipe(ts(tsProject));

return tsResult.js.pipe(gulp.dest('./'));

});

tsconfig content:

 {
  "compilerOptions": {
    "target": "es5",
    "module": "system",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  },
  "exclude": [
    "node_modules",
    "Scripts"
  ]
}

And my task runner console:

angular\chatApp.ts(5,21): error TS2305: Module '"C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/core"' has no exported member 'Scope'. angular\nominationApp.ts(1,21): error TS2305: Module '"C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/core"' has no exported member 'Scope'. angular\notificationApp.ts(1,33): error TS2305: Module '"C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/core"' has no exported member 'Scope'. angular\searchApp.ts(4,21): error TS2305: Module '"C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/core"' has no exported member 'Scope'. angular\teamRegisterApp.ts(1,21): error TS2305: Module '"C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/core"' has no exported member 'Scope'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/platform/browser.d.ts(77,90): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/common/pipes/async_pipe.d.ts(25,38): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/core/application_ref.d.ts(83,60): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/core/application_ref.d.ts(83,146): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/core/application_ref.d.ts(96,51): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/core/application_ref.d.ts(96,147): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/core/application_ref.d.ts(133,90): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/core/application_ref.d.ts(171,81): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/core/change_detection/parser/locals.d.ts(3,14): error TS2304: Cannot find name 'Map'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/core/change_detection/parser/locals.d.ts(4,42): error TS2304: Cannot find name 'Map'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/core/debug/debug_node.d.ts(14,13): error TS2304: Cannot find name 'Map'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/core/debug/debug_node.d.ts(24,17): error TS2304: Cannot find name 'Map'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/core/debug/debug_node.d.ts(25,17): error TS2304: Cannot find name 'Map'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/core/di/provider.d.ts(436,103): error TS2304: Cannot find name 'Map'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/core/di/provider.d.ts(436,135): error TS2304: Cannot find name 'Map'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/core/linker/compiler.d.ts(12,50): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/core/linker/compiler.d.ts(16,41): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/core/linker/dynamic_component_loader.d.ts(108,136): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/core/linker/dynamic_component_loader.d.ts(156,150): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/core/linker/dynamic_component_loader.d.ts(197,128): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/core/linker/dynamic_component_loader.d.ts(203,127): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/core/linker/dynamic_component_loader.d.ts(204,141): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/core/linker/dynamic_component_loader.d.ts(205,119): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/core/render/api.d.ts(13,13): error TS2304: Cannot find name 'Map'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/core/render/api.d.ts(14,84): error TS2304: Cannot find name 'Map'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/facade/async.d.ts(27,33): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/facade/async.d.ts(28,45): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/facade/collection.d.ts(1,25): error TS2304: Cannot find name 'MapConstructor'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/facade/collection.d.ts(2,25): error TS2304: Cannot find name 'SetConstructor'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/facade/collection.d.ts(4,27): error TS2304: Cannot find name 'Map'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/facade/collection.d.ts(4,39): error TS2304: Cannot find name 'Map'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/facade/collection.d.ts(7,9): error TS2304: Cannot find name 'Map'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/facade/collection.d.ts(8,30): error TS2304: Cannot find name 'Map'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/facade/collection.d.ts(11,43): error TS2304: Cannot find name 'Map'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/facade/collection.d.ts(12,27): error TS2304: Cannot find name 'Map'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/facade/collection.d.ts(14,23): error TS2304: Cannot find name 'Map'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/facade/collection.d.ts(15,25): error TS2304: Cannot find name 'Map'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/facade/collection.d.ts(95,41): error TS2304: Cannot find name 'Set'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/facade/collection.d.ts(96,22): error TS2304: Cannot find name 'Set'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/facade/collection.d.ts(97,25): error TS2304: Cannot find name 'Set'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/facade/lang.d.ts(13,17): error TS2304: Cannot find name 'Map'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/facade/lang.d.ts(14,17): error TS2304: Cannot find name 'Set'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/facade/lang.d.ts(78,59): error TS2304: Cannot find name 'Map'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/facade/promise.d.ts(2,14): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/facade/promise.d.ts(7,32): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/facade/promise.d.ts(8,38): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/facade/promise.d.ts(9,35): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/facade/promise.d.ts(9,93): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/facade/promise.d.ts(10,34): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/facade/promise.d.ts(11,32): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/facade/promise.d.ts(11,149): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/facade/promise.d.ts(12,43): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/platform/browser/browser_adapter.d.ts(75,33): error TS2304: Cannot find name 'Map'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/angular2/src/platform/dom/dom_adapter.d.ts(85,42): error TS2304: Cannot find name 'Map'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/rxjs/CoreOperators.d.ts(35,67): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/rxjs/CoreOperators.d.ts(50,66): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/rxjs/CoreOperators.d.ts(89,67): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/rxjs/CoreOperators.d.ts(94,38): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/rxjs/CoreOperators.d.ts(94,50): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/rxjs/Observable.d.ts(46,62): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/rxjs/Observable.d.ts(47,42): error TS2304: Cannot find name 'Iterator'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/rxjs/Observable.d.ts(103,74): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/rxjs/Observable.d.ts(103,84): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/rxjs/Observable.d.ts(143,66): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/rxjs/Observable.d.ts(158,65): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/rxjs/Observable.d.ts(201,66): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/rxjs/Observable.d.ts(206,38): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/rxjs/Observable.d.ts(206,50): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/rxjs/observable/ForkJoinObservable.d.ts(6,50): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/rxjs/observable/ForkJoinObservable.d.ts(7,58): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/rxjs/observable/FromObservable.d.ts(7,38): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/rxjs/observable/FromObservable.d.ts(7,51): error TS2304: Cannot find name 'Iterator'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/rxjs/observable/PromiseObservable.d.ts(9,31): error TS2304: Cannot find name 'Promise'. C:/Projects/hrajemevolejbal/HrajemeVolejbal/node_modules/rxjs/observable/PromiseObservable.d.ts(10,26): error TS2304: Cannot find name 'Promise'.

Every gulps are currently in latest version. Angular 2 is beta 7. Can You help me, where is problem? Very thanks.

like image 445
Petr Tomášek Avatar asked Feb 25 '16 15:02

Petr Tomášek


4 Answers

Many of your errors can be fixed by referencing the browser.d.ts declaration file in the TypeScript file that calls bootstrap:

///<reference path="../node_modules/angular2/typings/browser.d.ts"/>

For the Scope errors, it's harder to say. What Scope class/interface are you trying to use?

like image 132
MatthewScarpino Avatar answered Oct 31 '22 17:10

MatthewScarpino


From @MattScarpino's answer, the angular2 package includes the necessary definitions. Adding this reference line to any of my typescript files seemed to solve the problem:

///<reference path="../node_modules/angular2/typings/browser.d.ts"/>

I found I could also add the definitions to my list of source files in gulpfile.js so the reference wasn't in my typescript files:

gulp.task('ts', function (done) {    
    var tsResult = gulp.src([
        'node_modules/angular2/typings/browser.d.ts', // ADDED
        "scripts/*.ts"
    ])
      .pipe(ts(tsProject), undefined, ts.reporter.fullReporter());
    return tsResult.js.pipe(gulp.dest('./wwwroot/appScripts'));
});
like image 37
Jason Goemaat Avatar answered Oct 31 '22 18:10

Jason Goemaat


In complement to the Matt's answer, you could try the following:

const gulp = require('gulp');
const ts = require('gulp-typescript');

var tsProject = ts.createProject('tsconfig.json', {
  typescript: require('typescript')
});

gulp.task('tscompile', function () {
  var tsResult = gulp.src('./app/**/*.ts')
                .pipe(ts(tsProject));
  return tsResult.js.pipe(gulp.dest('./'));
});

This allows me to compile all the files under my app folders.

like image 2
Thierry Templier Avatar answered Oct 31 '22 17:10

Thierry Templier


If compiling just not work with gulp, but in an IDE like Visual Studio, the IDE could be a help to find out what reference you have to add to your bootstrap file.

In my case, the errors looked like this:

node_modules/@angular/core/src/linker/dynamic_component_loader.d.ts(113,139): error TS2304: Cannot find name 'Promise'.

I went to that file in VS, followed the reference (F12) and came to the definition, that was in typings/globals/core-js/index.d.ts. So I added this as reference in my bootstap typescript file:

///<reference path="../../typings/globals/core-js/index.d.ts"/>

like image 1
martinoss Avatar answered Oct 31 '22 16:10

martinoss