簡體   English   中英

TypeScript 編譯中缺少 home.component.spec.ts 錯誤。 請通過“文件”或“包含”屬性確保它在您的 tsconfig 中

[英]Error home.component.spec.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property

運行 ng test 時,TypeScript 編譯中缺少以下錯誤 home.component.spec.ts。 請通過“文件”或“包含”屬性確保它在您的 tsconfig 中。

項目結構

Project/
|-- src/
|   |-- app/
|   |   |-- home/
|   |   |   |-- home.component.spec.ts  
|   |   |-- app-main.component.spec.ts
|   |-- test.ts
|   |-- tsconfig.spec.json
|-- angular.json
|-- package.json
|-- tsconfig.json

tsconfig.spec.json

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/spec",
    "types": [
      "jasmine",
      "node"
    ]
  },
  "files": [
    "test.ts",
    "polyfills.ts",
    "app/app-main.component.spec.ts" 
    // explicitly targetting spec.ts file works, 
    // but I want to add them to the include property
    // "app/home/home.component.spec.ts" // this fixes it ...
  ],
  "include": [
    "**/*.spec.ts", // can't find app/app-main.component.spec.ts
    "app/*.spec.ts", // can't find app/app-main.component.spec.ts
    "**/**/*.spec.ts", // can't find app/home/home.component.spec.ts
    "app/home/*.spec.ts", // can't find app/home/home.component.spec.ts
    "**/*.d.ts"
  ]
}

它僅在我顯式添加規范文件時才有效,我想將這些文件/目錄添加到包含塊中,因此我不需要逐個顯式添加規范文件。

但是無論我嘗試在包含部分中添加什么,它都不起作用。

您必須在 tsconfig.spec.json 文件中從 tsconfig.json 重新注冊路徑。

例如,如果您的 tsconfig.json 文件中有以下內容

{
...
"paths": {
   "@/*": [
   "./*",
   "app/*",
   "src/app/*",
   "../node_modules/*"
  ]
}
...
}

這也需要在您的 tsconfig.spec.json 文件中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM