Home > Back-end >  spec.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the
spec.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the

Time:02-07

I got following error when running ng test or ng test --include src/folder/component-name.component.spec.ts

Error Message

  • Error: Module build failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js): Error: component-file.component.spec.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property. at /node_modules/@ngtools/webpack/src/ivy/loader.js:60:26 at processTicksAndRejections (node:internal/process/task_queues:96:5) at runNextTicks (node:internal/process/task_queues:65:3) at processImmediate (node:internal/timers:437:9)

tsconfig.spec.json

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/spec",
    "baseUrl": "./",
    "module": "commonjs",
    "target": "es5",
    "types": [
      "jasmine",
      "node"
    ]
  },
  "files": [
    "test.ts",
    "polyfills.ts"
  ],
  "include": [
    "**/*.spec.ts",
    "**/*.d.ts"
  ]
}

tsconfig.app.json

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

tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "importHelpers": true,
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "target": "es6",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2015",
      "es7",
      "dom"
    ],
    "module": "esnext",
    "allowSyntheticDefaultImports": true,
    "skipLibCheck": true,
  },
  "include": [
    "src/**/*",
  "exclude": [
    "node_modules",
    "**/*.spec.ts"
  ]
}

I guess this error, the test-component used lazy-module..,

CodePudding user response:

You're excluding any spec.ts files from compilation. Remove this line from the exclude arrays.

"**/*.spec.ts"
  •  Tags:  
  • Related