我不确定这是一个gulp问题,打字稿问题还是Angular 2问题。
我目前正在使用Angular 2 Beta 6.
这是我的打字稿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"
]
}
My Angular 2 bootstrap文件,其中包含角度测试版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文件仅包含模块变量的声明,作为@component
装饰器上带有module属性的角度6中的问题的解决方法。我不知道它是否是一个原因,但顶部的引用仅在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
但是,如果我进入我的一个打字稿文件,并进行有效的更改或只是改变这样的空白......
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
答案 0 :(得分:6)
添加
/// <reference path="node_modules/angular2/typings/browser.d.ts" />
在主TS文件中。
另见https://github.com/angular/angular/issues/7280#issuecomment-188777966