使用gulp-typescript在VS2015中不显示Typescript编译错误

时间:2016-05-24 22:18:15

标签: typescript visual-studio-2015 gulp gulp-typescript

这是几天前工作正常的事情,所以我不确定自那时以来发生了什么变化(除了更新到ASP.NET Core RC2并为我记得的VS2015安装一些扩展)

问题是当从VS2015运行Gulp任务来编译我的打字稿文件时,如果出现错误,例如:

[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至少在PATH中使用相同的打字稿编译器,这应该不是问题。这也是最新版本,但我尝试过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"

没有运气。

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

如果我从gulp任务中删除所有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或我的gulp-typescript可能有什么问题吗?

更新:我尝试使用gulp-tsc代替gulp-typescript,效果很好。 所以问题必须是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));
});

2 个答案:

答案 0 :(得分:4)

我至少找到了部分答案。如果从nodejs命令提示符运行gulp-typescript,它将显示错误。 gulp-typescript打印错误消息的方式并没有在visual studio task runner中显示。

如果我将用于打字稿的记者更改为此,则显示错误就好了(将此函数添加到您的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()))
});

答案 1 :(得分:3)

如果您安装了Microsoft .Net Core 1.0.0 RC2工具预览1。看起来有问题:After installing Preview 1 of the tooling, TypeScript errors aren't shown #526

更新.Net Core 1 / Tooling Preview 2发布后

更新到/安装.Net Core 1.0的发布版本更新了Tooling to Preview 2解决了这个问题。

enter image description here

在此之前卸载工具预览1并重新安装vs 2015的Web开发工具可以解决未显示错误详细信息的问题。

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

  1. 卸载' Microsoft .Net Core 1.0.0 RC2 - VS 2015工具预览1' enter image description here
  2. 在添加/删除visual studio中重新安装Visual Studio 2015的Web开发工具,修改。 enter image description here
  3. 执行此操作后,我可以再次在Task Runner Explorer中看到typescript错误消息。 enter image description here

相关问题