ivogabe / gulp-typescript

A TypeScript compiler for gulp with incremental compilation support.
MIT License
839 stars 129 forks source link

esModuleInterop: true won't be taken into account #628

Closed antoniolibrada closed 4 years ago

antoniolibrada commented 5 years ago

Expected behavior: I have a tsconfig.json file with the flag esModuleInterop: true in it. When I compile the files using gulp-typescript, seems to ignore that option and I had to explicitly write pipe(ts({esModuleInterop: true})). Is that intended? Actual behavior: I would expect that the gulp-typescript call takes the tsconfig.json options into account when transpiling. Your gulpfile:

Include your gulpfile, or only the related task (with ts.createProject).

    gulp.task('transpile-webapp', function () {
        return gulp.src('./src/main/webapp/**/*.ts')
            .pipe(ts({esModuleInterop: true}))
            .pipe(gulp.dest('./target/webapp'));
    });

tsconfig.json

Include your tsconfig, if related to this issue.

{
  "compilerOptions": {
    "esModuleInterop": true,
    "preserveConstEnums": true,
    "strictNullChecks": true,
    "sourceMap": true,
    "allowJs": true,
    "target": "ES2016",
    "module": "CommonJS",
    "outDir": ".build",
    "moduleResolution": "node",
    "lib": ["es2015"],
    "rootDir": "./"
  }
}

Code

Include your TypeScript code, if necessary.

ivogabe commented 4 years ago

With your configuration, you are not using the tsconfig file at all, hence your settings are not used. To use your tsconfig file, you must first create a project, outside the gulp task, using:

const tsProject = ts.createProject('tsconfig.json');

Inside the gulp task you should then use tsProject() instead of ts().