简体   繁体   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

When running ng test I get the following error home.component.spec.ts is missing from the TypeScript compilation.运行 ng test 时,TypeScript 编译中缺少以下错误 home.component.spec.ts。 Please make sure it is in your tsconfig via the 'files' or 'include' property.请通过“文件”或“包含”属性确保它在您的 tsconfig 中。

Project structure项目结构

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 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"
  ]
}

It works only when I Add the spec files explicitly, I want to add those files/directory's to the include block so I don't need to explicitly add the spec files one by one.它仅在我显式添加规范文件时才有效,我想将这些文件/目录添加到包含块中,因此我不需要逐个显式添加规范文件。

But whatever I try to add in the include section it is not working.但是无论我尝试在包含部分中添加什么,它都不起作用。

You have to re-register the path from your tsconfig.json in your tsconfig.spec.json file.您必须在 tsconfig.spec.json 文件中从 tsconfig.json 重新注册路径。

For example, if you have the following in your tsconfig.json file例如,如果您的 tsconfig.json 文件中有以下内容

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

This also needs to be in your tsconfig.spec.json file.这也需要在您的 tsconfig.spec.json 文件中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我该如何解决“错误:TypeScript 编译中缺少 \\src\\main.ts”。 - How can i solve "Error: \src\main.ts is missing from the TypeScript compilation." Webpack:TypeScript 编译中缺少。 …在 AngularCompilerPlugin.getCompiledFile - Webpack:is missing from the TypeScript compilation. …at AngularCompilerPlugin.getCompiledFile 如何在我的Jenkins构建中排除/包含某些component.spec.ts文件 - How do I exclude/include certain component.spec.ts files from running in my Jenkins build 如何在 tsconfig.json 中排除以“.spec.ts”结尾的文件 - How to exclude files ending in '.spec.ts' in tsconfig.json Angular 13.2。 错误:仅将入口点添加到 tsconfig 中的“文件”或“包含”属性 - Angular 13.2. error: Add only entry points to the 'files' or 'include' properties in your tsconfig 在 tsc TypeScript 编译中包含 CSS 文件 - Include CSS files in tsc TypeScript compilation ReactJS 错误:确保传递与组件构造函数相同的 props - ReactJS error: make sure to pass up the same props that your component's constructor was passed 错误:无法获取 Firebase 项目构建。 请确保该项目存在并且您的帐户有权访问它 - Error: Failed to get Firebase project build. Please make sure the project exists and your account has permission to access it 如何纠正 Typescript 编译错误 TS5012 - How to rectify Typescript compilation error TS5012 当我在 ts 代码中出现错误时,如何使用 tsconfig 文件强制 TypeScript 不编译为 JS? - How to force TypeScript to not compile to JS when I have an error in ts code, with tsconfig file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM