gulp-typescript 在保存时发出错误,但在后续保存时没问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35580944/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 03:18:14  来源:igfitidea点击:

gulp-typescript emitting errors upon save, but is fine with subsequent saves

typescriptgulpangular

提问by twilliams

I'm not really sure if this is a gulp issue, a typescript issue or an Angular 2 issue.

我不确定这是 gulp 问题、打字稿问题还是 Angular 2 问题。

I am using Angular 2 Beta 6 currently.

我目前使用的是 Angular 2 Beta 6。

This is my typescript gulp task.

这是我的打字稿 gulp 任务。

var tsProject = p.typescript.createProject("tsconfig.json");

gulp.task("client-scripts", function () {
    return gulp.src(paths.client.root + "**/*.ts")
        .pipe(p.cached("client-scripts"))
        .pipe(p.typescript(tsProject))
        .pipe(gulp.dest(paths.webroot.root));
});

And this is my tsconfig file.

这是我的 tsconfig 文件。

{
  "compilerOptions": {
    "noImplicitAny": true,
    "noEmitOnError": true,
    "removeComments": false,
    "sourceMap": false,
    "target": "es5",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "module": "commonjs",
    "moduleResolution": "node"
  },
  "exclude": [
    "node_modules",
    "wwwroot"
  ]
}

My Angular 2 bootstrap file, which includes some typings that are required for beta 6 of angular. I think this is one area where the problem could be happening.

我的 Angular 2 引导程序文件,其中包括一些 angular 测试版 6 所需的类型。我认为这是可能发生问题的一个领域。

///<reference path="../../node_modules/angular2/typings/browser.d.ts"/>
///<reference path="../../typings/shim.d.ts"/>

import { bootstrap } from "angular2/platform/browser";
import { ROUTER_PROVIDERS } from "angular2/router";
import { HTTP_PROVIDERS } from "angular2/http";
import { DataPlatformComponent } from "./dataPlatform.component";
import "rxjs/add/operator/map";

bootstrap(DataPlatformComponent, [ROUTER_PROVIDERS, HTTP_PROVIDERS]);

That shim file only contains a declaration of a module variable, as a workaround to an issue in angular 6 with the module property on the @componentdecorator. I don't know if it might be a reason, but those references at the top are only on the boot.ts file and not any other subsequent ts file I am saving.

该 shim 文件仅包含模块变量的声明,作为解决 angular 6 中@component装饰器上的模块属性问题的一种解决方法。我不知道这是否是一个原因,但顶部的那些引用仅在 boot.ts 文件中,而不是我正在保存的任何其他后续 ts 文件。

Upon initial run of my gulp build process everything is peachy...

在我的 gulp 构建过程的初始运行时,一切都很好......

[08:41:28] Starting 'entry'...
[08:41:28] Starting 'cleanup'...
[08:41:28] Finished 'entry' after 2.82 ms
[08:41:28] Finished 'cleanup' after 74 ms
[08:41:28] Starting 'initialize'...
[08:41:28] Starting 'vendor-scripts'...
[08:41:28] Starting 'vendor-content'...
[08:41:28] Starting 'client-scripts'...
[08:41:28] Starting 'client-nonscripts'...
[08:41:28] Starting 'client-sass'...
[08:41:28] Finished 'initialize' after 21 ms
[08:41:28] Finished 'vendor-scripts' after 176 ms
[08:41:28] Finished 'vendor-content' after 185 ms
[08:41:28] Finished 'client-sass' after 235 ms
[08:41:30] Finished 'client-scripts' after 2.31 s
[08:41:30] Finished 'client-nonscripts' after 2.3 s

But if I go into one of my typescript files, and make a valid change or just a whitespace change like from this...

但是,如果我进入我的一个打字稿文件,并进行有效更改或只是像这样更改空格...

export class DataPlatformComponent {
}

to this

对此

export class DataPlatformComponent {

}

I get a huge list of errors in my gulp output window. The two following lists are only snippets.

我在我的 gulp 输出窗口中收到了大量错误列表。以下两个列表只是片段。

[08:59:08] Starting 'client-scripts'...
C:/Github/Data-Platform/src/DataPlatform/client/platform/dashboard/dashboard.component.ts(4,15): error TS2304: Cannot find name 'module'.
client\platform\dataplatform.component.ts(8,15): error TS2304: Cannot find name 'module'.
[08:59:10] TypeScript: 62 semantic errors
C:/Github/Data-Platform/src/DataPlatform/client/platform/report catalog/details/chip.component.ts(6,15): error TS2304: Cannot find name 'module'.
C:/Github/Data-Platform/src/DataPlatform/client/platform/report catalog/details/reportDetails.component.ts(7,15): error TS2304: Cannot find name 'module'.
[08:59:10] TypeScript: emit failed
C:/Github/Data-Platform/src/DataPlatform/client/platform/report catalog/main/navigation.component.ts(8,15): error TS2304: Cannot find name 'module'.

Mostly those module error complaints and rxjs complaints.

主要是那些模块错误投诉和 rxjs 投诉。

[08:59:10] Finished 'client-scripts' after 2.08 s
C:/Github/Data-Platform/src/DataPlatform/client/platform/shell/navigation.component.ts(7,15): error TS2304: Cannot find name 'module'.
C:/Github/Data-Platform/src/DataPlatform/node_modules/angular2/src/core/change_detection/parser/locals.d.ts(3,14): error TS2304: Cannot find name 'Map'.
C:/Github/Data-Platform/src/DataPlatform/node_modules/angular2/src/core/change_detection/parser/locals.d.ts(4,42): error TS2304: Cannot find name 'Map'.
C:/Github/Data-Platform/src/DataPlatform/node_modules/angular2/src/core/debug/debug_node.d.ts(14,13): error TS2304: Cannot find name 'Map'.
C:/Github/Data-Platform/src/DataPlatform/node_modules/angular2/src/core/debug/debug_node.d.ts(24,17): error TS2304: Cannot find name 'Map'.

If I save the file again, things are fine... but it seems to have interrupted my file emits, and so I have to restart the entire build process.

如果我再次保存文件,一切都很好……但它似乎中断了我的文件发出,因此我必须重新启动整个构建过程。

[09:02:50] Starting 'client-scripts'...
[09:02:51] Finished 'client-scripts' after 1.28 s

As requested, here is my directory structure... with most of the files I think are unnecessary omitted.

根据要求,这是我的目录结构......我认为大部分文件都被省略了。

|-DataPlatform
    |-wwwroot
    |-client
        |-platform
            |-content
            |-dashboard
            |-report catalog
            |-shared
            |-shell
            boot.ts
            dataPlatform.component.ts
            dataPlatform.template.html
        index.html
    |-node_modules
    |-typings
        shim.d.ts
    gulpfile.js
    package.json
    project.json
    tsconfig.json
    Startup.cs

回答by Günter Z?chbauer

Add

添加

/// <reference path="node_modules/angular2/typings/browser.d.ts" />

in the main TS file.

在主 TS 文件中。

See also https://github.com/angular/angular/issues/7280#issuecomment-188777966

另见https://github.com/angular/angular/issues/7280#issuecomment-188777966