我在gulp输出中遇到了这些恼人的“错误”错误:
$ gulp build-ts
[19:30:09] Using gulpfile ~/Learning/vision-boilerplate/gulpfile.js
[19:30:09] Starting 'build-ts'...
[19:30:09] Finished 'build-ts' after 6.33 ms
ng/app.component.ts(1,27): error TS2307: Cannot find module '@angular/core'.
ng/app.component.ts(6,12): error TS2304: Cannot find name 'module'.
ng/app.module.ts(1,26): error TS2307: Cannot find module '@angular/core'.
ng/app.module.ts(2,31): error TS2307: Cannot find module '@angular/platform-browser'.
ng/app.module.ts(3,31): error TS2307: Cannot find module '@angular/common'.
ng/app.module.ts(4,30): error TS2307: Cannot find module '@angular/router'.
ng/app.module.ts(5,28): error TS2307: Cannot find module '@angular/http'.
ng/app.routes.ts(1,24): error TS2307: Cannot find module '@angular/router'.
ng/dashboard/dashboard.component.ts(1,27): error TS2307: Cannot find module '@angular/core'.
ng/dashboard/dashboard.component.ts(7,13): error TS2304: Cannot find name 'module'.
ng/dashboard/dashboard.module.ts(1,26): error TS2307: Cannot find module '@angular/core'.
ng/dashboard/dashboard.module.ts(2,30): error TS2307: Cannot find module '@angular/common'.
ng/dashboard/dashboard.module.ts(4,24): error TS2307: Cannot find module '@angular/core'.
ng/dashboard/dashboard.routes.ts(1,23): error TS2307: Cannot find module '@angular/router'.
ng/input/input-module/input-module.component.ts(1,27): error TS2307: Cannot find module '@angular/core'.
ng/input/input-module/input-module.component.ts(2,23): error TS2307: Cannot find module '@angular/core'.
ng/input/input-module/input-module.component.ts(11,13): error TS2304: Cannot find name 'module'.
ng/input/input-module/input-module.service.ts(1,28): error TS2307: Cannot find module '@angular/core'.
ng/input/input-module/input-module.service.ts(2,47): error TS2307: Cannot find module '@angular/http'.
ng/input/input-module/input-module.service.ts(3,26): error TS2307: Cannot find module 'rxjs/Rx'.
ng/input/input.component.ts(1,27): error TS2307: Cannot find module '@angular/core'.
ng/input/input.component.ts(2,24): error TS2307: Cannot find module '@angular/core'.
ng/input/input.component.ts(9,13): error TS2304: Cannot find name 'module'.
ng/input/input.module.ts(1,26): error TS2307: Cannot find module '@angular/core'.
ng/input/input.module.ts(2,30): error TS2307: Cannot find module '@angular/common'.
ng/input/input.routes.ts(1,23): error TS2307: Cannot find module '@angular/router'.
ng/input/input.service.ts(1,28): error TS2307: Cannot find module '@angular/core'.
ng/input/input.service.ts(2,31): error TS2307: Cannot find module '@angular/http'.
ng/input/input.service.ts(16,16): error TS2304: Cannot find name 'Promise'.
ng/main.ts(1,40): error TS2307: Cannot find module '@angular/platform-browser-dynamic'.
ng/shared/navbar/navbar.component.ts(1,27): error TS2307: Cannot find module '@angular/core'.
ng/shared/navbar/navbar.component.ts(7,13): error TS2304: Cannot find name 'module'.
ng/shared/shared.module.ts(1,47): error TS2307: Cannot find module '@angular/core'.
ng/shared/shared.module.ts(2,30): error TS2307: Cannot find module '@angular/common'.
ng/shared/shared.module.ts(3,29): error TS2307: Cannot find module '@angular/forms'.
ng/shared/shared.module.ts(4,30): error TS2307: Cannot find module '@angular/router'.
[19:30:10] TypeScript: 36 semantic errors
[19:30:10] TypeScript: emit succeeded (with errors)
我的应用程序实际编译并正常工作,但我真的想摆脱这些错误。这是我的build-ts
任务:
gulp.task('build-ts', function() {
var result = gulp.src(appDev + '**/*.ts')
.pipe(inlineNg2Template({useRelativePaths: true}))
.pipe(sourcemaps.init())
.pipe(typescript(tsProject))
.pipe(sourcemaps.write())
.pipe(gulp.dest(appProd));
});
我的tsconfig.json
:
$ cat tsconfig.json
{
"compilerOptions": {
"target": "ES5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"outDir": "./web/app"
},
"filesGlob": [
"./ng/**/*.ts",
"!./node_modules/**/*.ts"
],
"exclude": [
"node_modules",
"typings/main",
"typings/main.d.ts"
],
"atom": {
"rewriteTsconfig": true
}
}
我的项目树看起来像这样:
$ tree -L 1
.
├── config
├── docker-compose.yml
├── Dockerfile
├── gulpfile.js
├── ng
├── node_modules
├── package.json
├── requirements.txt
├── run.py
├── tsconfig.json
├── typings
├── typings.json
├── vision_modules
└── web
所有angular2依赖项都应该在node_modules
中。就像我说的那样,应用程序实际上完全符合预期。
答案 0 :(得分:0)
你可能错过了打字稿的打字。我将它们加载到 main.ts
/// <reference path="../../typings/index.d.ts" />