简体   繁体   English

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

[英]Typescript compilation errors not being displayed in VS2015 using gulp-typescript

This is something that some days ago was working fine, so I am not sure what has changed since then (other than updating to ASP.NET Core RC2 and installing some extension for VS2015 as I recall) 这是几天前工作正常的事情,所以我不确定自那时以来发生了什么变化(除了更新到ASP.NET Core RC2并为我记得安装VS2015的某些扩展)

The issue is that when running from VS2015 a Gulp task to compile my typescript files, if there is an error it shows for example: 问题是当从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.

without any description of the error. 没有任何错误描述。

in CMD: 在CMD:

$ tsc -v
Version 1.8.10

In VS2015 Package Manager console: 在VS2015 Package Manager控制台中:

PM> tsc -v
Version 1.8.10

so I think VS2015 is at least using the same typescript compiler in PATH and that shouldn't be a problem. 所以我认为VS2015至少在PATH中使用相同的打字稿编译器,这应该不是问题。 Also this is the latest version but I have tried with 1.7 and the same thing happens. 这也是最新版本,但我尝试过1.7,同样的事情发生了。

My gulp task: 我的任务:

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));
});

And I am using: 我正在使用:

"gulp-typescript": "2.10.0"

although I have tried with the latest: 虽然我尝试过最新的:

"gulp-typescript": "2.13.4"

with no luck. 没有运气。

As I understood I don't need a tsconfig.json at the root of my project since I am using gulp-typescript and I am passing already the compilerOptions in the gulp task itself, so I have deleted the tsconfig.json I had because it does not seem to be used. 据我所知,我不需要在项目的根目录下使用tsconfig.json,因为我正在使用gulp-typescript typescript而且我已经在gulp任务本身传递了compilerOptions,所以我删除了tsconfig.json,因为它似乎没有被使用。

If I remove all the compilerOptions from my gulp task: 如果我从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));
});

I get more semantic errors also without description. 我没有描述也得到更多的语义错误。

[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.

so the options are definitely being used. 所以选项肯定被使用。

And if in my CMD I go to the folder where I have a typescript and try to compile it with: 如果在我的CMD中,我会转到我有一个打字稿的文件夹,并尝试使用以下命令编译它:

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

I can properly see all the typescript compilation errors. 我可以正确地看到所有打字稿编译错误。

Any idea what might be wrong in my VS2015 or my gulp-typescript? 知道我的VS2015或我的gulp-typescript可能有什么问题吗?

UPDATE : I have tried with gulp-tsc instead gulp-typescript and it works well. 更新 :我尝试使用gulp-tsc而不是gulp-typescript,它运行良好。 So the problem must be with 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));
});

I've found part of the answer at least. 我至少找到了部分答案。 if you run gulp-typescript from a nodejs command prompt it will show you the errors. 如果从nodejs命令提示符运行gulp-typescript,它将显示错误。 The way gulp-typescript is printing the error messages however isn't shown in visual studio task runner. 然而,gulp-typescript打印错误消息的方式在visual studio task runner中没有显示。

If i change the reporter used for typescript to this it shows the errors just fine (add this function to your gulpfile.js) 如果我将用于打字稿的记者更改为此,则显示错误就好了(将此函数添加到您的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
    };
}

And now you can use the reporter like this 现在你可以像这样使用记者

var ts = require("gulp-typescript")

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

If you have Microsoft .Net Core 1.0.0 RC2 Tooling Preview 1 installed. 如果您安装了Microsoft .Net Core 1.0.0 RC2工具预览1。 Looks like there is an issue: After installing Preview 1 of the tooling, TypeScript errors aren't shown #526 看起来有一个问题: 在安装工具的预览1后,未显示TypeScript错误#526

Updated After release of .Net Core 1 / Tooling Preview 2 更新后发布.Net Core 1 / Tooling Preview 2

Updating to / Installing the release version of .Net Core 1.0 which updates the Tooling to Preview 2 resolves this issue. 更新到/安装.Net Core 1.0的发布版本更新了Tooling to Preview 2可以解决此问题。

在此输入图像描述

Prior to this uninstalling the tooling preview 1 and re-installing web development tools for vs 2015 would resolve the issue where error details are not shown. 在此之前卸载工具预览1并重新安装vs 2015的Web开发工具将解决未显示错误详细信息的问题。

I had the same issue. 我遇到过同样的问题。 Since I was not using the functionality of .Net Core 1 RC2 Preview. 因为我没有使用.Net Core 1 RC2 Preview的功能。 I was able to resolve the issue with typescript errors not being shown with the workaround mentioned in the bug report on Github by: 我能够通过Github上的错误报告中提到的解决方法来解决typecript错误没有显示的问题:

  1. uninstalling 'Microsoft .Net Core 1.0.0 RC2 - VS 2015 Tooling Preview 1' 卸载'Microsoft .Net Core 1.0.0 RC2 - VS 2015 Tooling Preview 1' 在此输入图像描述
  2. Reinstalling Web Development tools for visual studio 2015 in add/remove visual studio , Modify. 在添加/删除visual studio中重新安装Visual Studio 2015的Web开发工具,修改。 在此输入图像描述

After doing so I could once again see typescript error messages in Task Runner Explorer. 这样做后,我可以再次在Task Runner Explorer中看到typescript错误消息。 在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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