2016-06-27 52 views
2

我正在开发的VisualStudio中的Angular2 /打字稿应用程序,并希望建立自己TS编译器,但每当我运行它,它发现错误,我没有得到有关它们的详细信息只是这样的:如何使gulp-typescript显示错误?

[16:22:23] Starting 'compile:typescript'... 
[16:22:26] TypeScript: 1 semantic error 
[16:22:26] TypeScript: emit failed 
[16:22:26] Finished 'compile:typescript' after 3.14 s 

我gulpfile.js是一种很大的,但相关的部分是在这里:

var gulp = require('gulp'); 
var del = require('del'); 
var ts = require("gulp-typescript"); 
var gutil = require("gulp-util"); 
var watchifiy = require('watchify'); 
var sourcemaps = require('gulp-sourcemaps'); 

// -------------------------- COMPILE TS --------------------------- 
gulp.task('compile:typescript', function() { 
    var tsResult = gulp.src('./Scripts/**/*.ts', { base: './Scripts' }) 
     .pipe(sourcemaps.init()) 
     .pipe(ts(
       ts.createProject('Scripts/tsconfig.json'), 
       undefined, 
       ts.reporter.fullReporter())); 

    return tsResult.js 
     .pipe(sourcemaps.write()) 
     .pipe(gulp.dest('./Scripts')); 
}) 

tsconfig.json:

{ 
    "compilerOptions": { 
    "target": "es5", 
    "module": "commonjs", 
    "moduleResolution": "node", 
    "sourceMap": true, 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "removeComments": false, 
    "noImplicitAny": false, 
    "noEmitOnError": true 
    }, 
    "exclude": [ 
    "node_modules", 
    "typings/globals", 
    "typings/index.d.ts" 
    ] 
} 

会感谢任何想法。

+0

它从nodejs命令提示符运行时是否正确显示错误?如果是这样看看这个:http://stackoverflow.com/a/37971172/40783 –

回答

1

更新

它看起来这是一个已知的bug,发现here

原始

我会建议使用gulp-debug包,它可以让你.pipe到您的任务并捕获标准输出。

调试乙烯基文件流,看看通过你的一口管道运行哪些文件

gulpfile.js

var debug = require("gulp-debug"); 
gulp.task('compile:typescript', function() { 
    var tsResult = gulp.src('./Scripts/**/*.ts', { base: './Scripts' }) 
     .pipe(sourcemaps.init()) 
     .pipe(debug()) // here... 
     .pipe(ts(
       ts.createProject('Scripts/tsconfig.json'), 
       undefined, 
       ts.reporter.fullReporter())); 

    return tsResult.js 
     .pipe(sourcemaps.write()) 
     .pipe(gulp.dest('./Scripts')); 
}) 

你需要给它添加到列表中的devDependenciespackage.json以便npm将安装它。

+1

谢谢你的答案。这显示我处理了哪些文件(我的所有.ts文件都是)。这如何让我更接近找到语义错误? –

+0

它看起来好像你已经在使用'fullreporter',它应该给你你正在寻找的错误信息。如果没有,那么可能没有任何额外的错误消息。 –

0

我遇到过类似的问题。从我的tsconfig.json文件中删除"noEmit": true, 解决了它。

尝试从您的帐户中删除"noEmitOnError": true或将其设置为false。