简体   繁体   中英

Getting ERROR in ./src/polyfills.ts Module build failed while running ng test - Angular 6

Somehow karma.config was missed in the existing angular project I am working with.

So I have added it manually and tried to run the test using the command ng test

While running the following error is displayed.

[./src/polyfills.ts] 699 bytes {polyfills} [built] [failed] [1 error]
[./src/test.ts] 990 bytes {main}
    + 228 hidden modules

ERROR in ./src/polyfills.ts
Module build failed: Error: C:\Projects\MyProject\src\polyfills.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
    at AngularCompilerPlugin.getCompiledFile (C:\C:\Projects\MyProject\node_modules\@ngtools\webpack\src\packages\ngtools\webpack\src\angular_compiler_plugin.ts:982:15)
    at plugin.done.then (C:\Projects\MyProject\node_modules\@ngtools\webpack\src\packages\ngtools\webpack\src\loader.ts:49:29)
    at process._tickCallback (internal/process/next_tick.js:68:7)
 @ multi ./src/polyfills.ts

I notice there are two tsconfig.json in the app, The first one is present under the project root folder and the content

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "module": "es2015",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ]
  }
}

The second one is present inside the src folder and the content is

{
    "compilerOptions": {
        "experimentalDecorators": true,
        "target": "es5",
        "allowJs": true
    }
}

I have tried to use include in any of those files to add src/polyfills.ts but no luck.

Can anyone guide how to fix this?

Angular version - 6

I found tsconfig.spec.json did not have polyfills.ts . So I have added it as below and the issue was resolved

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

This post: Module build failed ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property helped me to validate the contents of tsconfig.json,tsconfig.app.json and tsconfig.spec.json.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM