2016-05-24 82 views
7

这是前几天工作正常的东西,所以我不确定自那以后发生了什么变化(除了更新到ASP.NET Core RC2并安装了一些扩展为VS2015我记得)使用gulp-typescript不会在VS2015中显示Typescript编译错误

的问题是,从VS2015运行咕嘟咕嘟任务时编译我打字原稿文件,如果有就说明例如一个错误:

[10:02:54] Compiling typescript into javascript 
[10:02:56] TypeScript: 1 semantic error 
[10:02:56] TypeScript: emit succeeded (with errors) 
[10:02:56] Finished 'compile' after 2.47 s 
Process terminated with code 0. 

没有任何错误描述。

在CMD:

$ tsc -v 
Version 1.8.10 

在VS2015包管理器控制台:

PM> tsc -v 
Version 1.8.10 

所以我认为VS2015至少使用路径相同的打字稿编译器和不应该是一个问题。这也是最新的版本,但我已经尝试过1.7,同样的事情发生。

我一饮而尽任务:

gulp.task('compile', function() { 
    log('Compiling typescript into javascript'); 
    return gulp 
      .src(config.allts) 
      .pipe($.sourcemaps.init()) 
      .pipe($.typescript({ 
       noImplicitAny: true, 
       target: 'ES5' 
      })) 
      .pipe($.sourcemaps.write('.')) 
      .pipe(gulp.dest(config.compileFolder)); 
}); 

,我使用:

"gulp-typescript": "2.10.0" 

虽然我已经用最新的尝试:

"gulp-typescript": "2.13.4" 

没有运气。

据我所知,我不需要在我的项目的根目录tsconfig.json,因为我使用gulp-typescript,我已经在gulp任务本身已经把compilerOptions,所以我已经删除了我有tsconfig.json因为它似乎没有被使用。

如果我删除所有从我一饮而尽任务compilerOptions:

gulp.task('compile', function() { 
    log('Compiling typescript into javascript'); 
    return gulp 
      .src(config.allts) 
      .pipe($.sourcemaps.init()) 
      .pipe($.typescript({ 
       //removed 
      })) 
      .pipe($.sourcemaps.write('.')) 
      .pipe(gulp.dest(config.compileFolder)); 
}); 

我得到更多的语义错误也没有说明。

[10:12:57] Compiling typescript into javascript 
[10:13:00] TypeScript: 184 semantic errors 
[10:13:00] TypeScript: emit succeeded (with errors) 
[10:13:01] Finished 'compile' after 3.83 s 
Process terminated with code 0. 

所以这些选项肯定被使用。

如果在我的CMD我去的地方,我有一个打字稿,并尝试编译它的文件夹:

C:/>Sample/app> tsc mytestfile.ts 

我可以正确地看到所有的打字稿编译错误。

任何想法什么可能是我的VS2015或我的吞食打字稿错?

UPDATE:我尝试过使用gulp-tsc代替gulp-typescript,它运行良好。 所以这个问题必须与一饮而尽,打字稿

gulp.task('compile', function() { 
    log('Compiling typescript into javascript'); 
    return gulp 
      .src(config.allts) 
      .pipe($.sourcemaps.init()) 
      .pipe($.tsc({ 
       noImplicitAny: true, 
       target: 'ES5' 
      })) 
      .pipe($.sourcemaps.write('.')) 
      .pipe(gulp.dest(config.compileFolder)); 
}); 
+0

我在队友的机器上遇到了与VS2015 + gulp-typecript相同的问题,他的终端显示了隐含的“N语义错误”。项目配置是相同的,但在我的终端上,我可以看到确切的错误说明。 – Cubius

+0

我目前的解决方法是在VS“错误列表”窗口中切换到“Build + IntelliSense”,并使用那里的信息来修复错误。 – user764754

回答

3

如果您安装了Microsoft .Net Core 1.0.0 RC2 Tooling Preview 1。貌似有一个问题:After installing Preview 1 of the tooling, TypeScript errors aren't shown #526

更新的.Net核心的版本1 /工具预览后2

更新到/安装的.Net核心1.0的发布版本,更新工装预览2所做出决议这个问题。

enter image description here

在此之前卸载工具预览1,并重新安装了VS 2015年就解决了其中的错误细节未显示的问题Web开发工具。

我有同样的问题。因为我没有使用.Net Core 1 RC2 Preview的功能。我能解决与未显示与在bug报告中提到Github上的解决方法打字稿错误的问题:

  1. 卸载“微软的.Net核心1.0.0 RC2 - 2015年VS工具预览1” enter image description here
  2. 在add/remove visual studio中重新安装Visual Studio 2015的Web开发工具,修改。 enter image description here

这样做,我可以再一次看到在任务运行资源管理器打字稿错误消息后。 enter image description here

4

我至少找到了部分答案。如果您从nodejs命令提示符运行gulp-typescript,它会向您显示错误。然而,gulp-typescript打印错误消息的方式在Visual Studio任务运行器中未显示。

如果我更改用于打字稿该记者则显示错误就好了(这个功能添加到您的gulpfile.js)

function visualStudioReporter() { 
    return { 
     error: function (error) { 
      //This works 
      gutil.log("Typescript: error", error.message); 
      //This isn't shown 
      console.error(error.message); 
     }, 
     finish: ts.reporter.defaultReporter().finish 
    }; 
} 

现在你可以使用记者这样

var ts = require("gulp-typescript") 

gulp.task("compile", function() { 
    gulp.src("./**/*.ts") 
     .pipe(ts(tsProject, undefined, visualStudioReporter())) 
}); 
+0

可能很明显,但是icymi'var gutil = require('gulp-util');'它指的是https://www.npmjs.com/package/gulp-util。真棒解决方案顺便说一句,谢谢! –