简体   繁体   中英

Never ending typescript compilation with gulp

I'm trying to compile my typescript files with gulp and gulp-typescript npm modules. I've already done that with many apps before, but never ran into that issue that I don't seem to be able to resolve by my own. The 'compile' task starts, but never ends. Here is my gulpfile.js:

var gulp = require('gulp');
var del = require('del');
var typescript = require('gulp-typescript');
var tscConfig = require('./tsconfig.json');
var exec = require('child_process').exec;
gulp.task('clean', function(){
    return del('./public/dist/**/*');
});
gulp.task('compile', ['clean'], function(){
    return gulp
        .src('./public/ts/**/*.ts')
        .pipe(typescript(tscConfig.compilerOptions))
        .pipe(gulp.dest('./public/dist'))
});
gulp.task('connect', function (cb) {
    exec('node server', function (err, stdout, stderr) {
        console.log(stdout);
    });
})
gulp.task('watch', function(){
    gulp.watch(['./public/ts/**/*.ts'], ['compile', 'connect'])
        .on('change', function(event){
            console.log('\x1b[33m', 'The file ' + event.path + 'has been modified.');
    });
});
gulp.task('default', ['watch', 'compile', 'connect']);

And here is my tsConfig.json file:

{
    "compilerOptions": {
        "outDir": "dist",
        "target": "es2015",
        "module": "system",
        "moduleResolution": "node",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "removeComments": false,
        "noImplicitAny": false
    },
      "exclude": [
          "node_modules",
          "typings/main",
          "typings/main.d.ts"
      ]
}

My architecture looks like:

\myapp
    \--public
        \--ts
        \--dist
        index.html
    gulpfile.js
    tsconfig.json

Everything but my 'compile' task seems to be working fine. Please, any idea why something's going wrong? I've been searching for hours, looking for differences with other working projects, but didn't find anything...

The 'compile' task starts, but never ends

You will have to share your code. You might want to create an issue at the official repo, something like this : https://github.com/Microsoft/TypeScript/issues/8401

If you do not want to share your code:

gulp.task('compile', ['clean'], function(){
    return gulp
        .src('myapp/ts/**/*.ts')
        .pipe(typescript(tscConfig.compilerOptions))
        .pipe(gulp.dest('myapp/dist'))
});

First of all, can you please verify the path in .src? it is passing myapp/ts/**/*.ts but in your architecture, the ts folder seems to exist with in the public folder under myapp so it should look like myapp/public/ts/**/*.ts

Ok, I got it. The issue came from my tsconfig.json file. The line "outDir": "dist" seemed to be overwriting my .pipe(gulp.dest('myapp/dist')) in gulpfile.js . Silly mistake, since I didn't need that line of code, but I copied/pasted it from an ancient project, and didn't think the compilerOptions should vary. Anyway, issue resolved, thanks for your answers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM