gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 17:48:58 24 4
gpt4 key购买 nike

我不确定这是 gulp 问题、typescript 问题还是 Angular 2 问题。

我目前正在使用 Angular 2 Beta 6。

这是我的 typescript 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));
});

这是我的 tsconfig 文件。

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

我的 Angular 2 Bootstrap 文件,其中包含 Angular 的 beta 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]);

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

在我的 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

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

export class DataPlatformComponent {
}

对此

export class DataPlatformComponent {

}

我在 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'.

主要是那些模块错误投诉和 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'.

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

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

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

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

最佳答案

添加

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

在主 TS 文件中。

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

关于typescript - gulp-typescript 在保存时发出错误,但在后续保存时没问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35580944/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com