Angular 2错误中缺少:TypeScript编译。请通过'files'或'include'属性确保它在您的tsconfig中

时间:2018-02-12 21:48:54

标签: typescript angular2-routing

付款-details.component.ts:

   import { Component, OnInit } from '@angular/core';

@Component({
      selector: 'app-payment-details',
      templateUrl: './payment-details.component.html',
      styleUrls: ['./payment-details.component.css']
    })
    export class PaymentDetailsComponent implements OnInit {
          constructor() { }    
      ngOnInit() {     }
    }



     import { PaymentDetailsComponent } from './Payment/payment-details/payment-details.component';
        import { NgModule } from '@angular/core';
        import { RouterModule, Routes } from '@angular/router';

应用-routing.module.ts:

const routes: Routes =  [

  {path : 'payment-details', component:  PaymentDetailsComponent  }
];
@NgModule({
  imports: [ RouterModule.forRoot(routes) ],
  exports: [ RouterModule ]

})


export class AppRoutingModule {}
src文件夹中的

tsConfig.app.Json:

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "baseUrl": "./",
    "module": "es2015",
    "types": []
  },
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ]
}

错误消息:

  

C:\ SRC \ SchoolsMadeEasy \ SRC \应用\付款\付款细节\付款details.component.ts   TypeScript编译中缺少。请确保它在   你的tsconfig通过'files'或'include'属性。

我正在松散地关注使用路由的英雄教程。我的代码没有编译的任何想法?

3 个答案:

答案 0 :(得分:1)

我知道这是一个古老的问题,但由于遇到类似的错误消息而遇到了这个问题。

在我的情况下,这是由于文件名和导入语句中对文件的引用不匹配引起的。

答案 1 :(得分:0)

您的打字稿文件位于何处?如果它位于/ src /文件夹之外,我相信tsconfig找不到它。

编辑:尝试在tsconfig文件中包含以下内容:

"src/**/*"

http://www.typescriptlang.org/docs/handbook/tsconfig-json.html

答案 2 :(得分:0)

我知道这是旧帖子,但这可能会帮助某人解决。

"preserveSymlinks": true添加到a​​ngular.json对我来说确实是骗人的。

"options": {
            "outputPath": "dist",
            "index": "src/index.html",
            "main": "src/main.ts",
            "tsConfig": "src/tsconfig.app.json",
            "progress": true,
            "polyfills": "src/polyfills.ts",
            "assets": [
              "src/assets",
              "src/favicon.ico",
              "src/web.config"
            ],
            "styles": [
              {
                "input": "node_modules/@angular/material/prebuilt-themes/indigo-pink.css"
              },
              {
                "input": "node_modules/@progress/kendo-theme-default/dist/all.css"
              },
              "./node_modules/ag-grid-community/dist/styles/ag-grid.css",
              "./node_modules/ag-grid-community/dist/styles/ag-theme-material.css",
              "./node_modules/ngx-bootstrap/datepicker/bs-datepicker.css",
              "src/styles.scss"
            ],
            "scripts": [],
            "preserveSymlinks": true
          }