【问题标题】:How to make gulp-typescript show errors?如何让 gulp-typescript 显示错误?
【发布时间】:2016-06-27 14:40:46
【问题描述】:

我正在 VisualStudio 中开发一个 Angular2/Typescript 应用程序,并想设置我自己的 ts 编译器,但每当我运行它并发现错误时,我都没有得到关于它们的详细信息:

[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"
  ]
}

如果有任何想法,将不胜感激。

【问题讨论】:

标签: typescript angular gulp gulp-typescript


【解决方案1】:

更新

看起来这是一个已知的错误,发现 here

原创

我建议使用gulp-debug 包,它允许您将.pipe 放入您的任务并捕获标准输出。

调试乙烯基文件流以查看通过 gulp 管道运行的文件

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

您需要将其添加到package.json 中的devDependencies 列表中,以便npm 安装它。

【讨论】:

  • 感谢您的回答。这向我显示了正在处理的文件(我所有的 .ts 文件都是)。这如何让我更接近发现语义错误?
  • 您似乎已经在使用fullreporter,它应该会为您提供您正在寻找的错误消息。如果没有,那么可能没有任何其他错误消息。
【解决方案2】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-22
    • 1970-01-01
    • 2019-08-02
    • 1970-01-01
    • 2015-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多