【问题标题】:Typescript compilation errors not being displayed in VS2015 using gulp-typescript使用 gulp-typescript 在 VS2015 中未显示 Typescript 编译错误
【发布时间】:2016-05-24 22:18:14
【问题描述】:

这是几天前工作正常的东西,所以我不确定从那以后发生了什么变化(除了更新到 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"

没有运气。

据我了解,我的项目根目录不需要 tsconfig.json,因为我使用的是gulp-typescript,并且我已经在 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));
});

【问题讨论】:

  • 我队友机器上的 VS2015 + gulp-typecript 也有同样的问题,他的终端显示神秘的N semantic errors。项目配置是相同的,但在我的终端上我可以看到确切的错误描述。
  • 我目前的解决方法是在VS“错误列表”窗口中切换到“Build + IntelliSense”,并使用那里的信息来修复错误。

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


【解决方案1】:

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

如果我将用于 typescript 的报告器更改为此,它会显示错误(将此函数添加到您的 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()))
});

【讨论】:

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

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

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

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

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

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

  1. 卸载“Microsoft .Net Core 1.0.0 RC2 - VS 2015 Tooling Preview 1”
  2. 在添加/删除 Visual Studio 中重新安装 Visual Studio 2015 的 Web 开发工具,修改。

这样做之后,我可以再次在 Task Runner Explorer 中看到 typescript 错误消息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-03
    • 2020-10-02
    • 1970-01-01
    • 1970-01-01
    • 2015-11-25
    • 1970-01-01
    • 1970-01-01
    • 2016-12-18
    相关资源
    最近更新 更多