aleczandru
aleczandru

Reputation: 5449

Setting up typescript using gulp-typescript results in multiple errors

Hi I am trying to configure gulp to compile my typescript files here is what I have so far:

const gulp = require('gulp');
const del = require('del');
const typescript = require('gulp-typescript');
const tscConfig = require('./tsconfig.json');
const util = require('gulp-util');

var paths = {
   npmSrc: "./node_modules/",
   libTarget: "./wwwroot/lib/",
   appTarget: "./wwwroot/app/"
}

gulp.task('tsBuild', function () {

    return gulp.src('App/**/*.ts')
        .pipe(typescript(tscConfig))
        .pipe(gulp.dest(paths.appTarget));
}

My tsConfig looks like this:

    {
  "compilerOptions": {
    "outDir": "./wwwroot/app/",
    "target": "es5",
    "module": "system",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "removeComments": false,
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": true
  },
  "exclude": [
    "node_modules",
    "wwwroot"
  ]
}

This are the error messages I am getting:

App\bootstrap.ts(1,25): error TS2307: Cannot find module 'angular2/platform/browser'.

App\template\template.component.ts(1,1): error TS1148: Cannot compile modules unless the '--module' flag is provided with a valid module type. Consider setting the 'module' compiler option in a 'tsconfig.json' file.

App\template\template.component.ts(1,25): error TS2307: Cannot find module 'angular2/core'. App\template\template.component.ts(8,14):

error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning.

It feels as if it is not reading the tsconfig file.My files do eventually get compiled correctly.

.Anyone has any ideea what I am doing wrong?

Upvotes: 0

Views: 923

Answers (2)

Amid
Amid

Reputation: 22332

Below is gulp task that should work fine:

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

gulp.task('tsBuild', function () 
{
    var tsProject = typescript.createProject('tsconfig.json');

    var tsResult = tsProject.src()
        .pipe(typescript(tsProject));  

    return tsResult.js.pipe(gulp.dest(paths.appTarget));
});

Its always easier to exclude unnecessary files in tsconfig instead of explicitly specifying all necessary ones.

Upvotes: 1

uthomas
uthomas

Reputation: 754

Try:

const tscConfig = require('./tsconfig.json').compilerOptions;

Upvotes: 0

Related Questions