簡體   English   中英

運行 ng 測試時在 ./src/polyfills.ts 模塊構建中出現錯誤 - Angular 6

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

我正在使用的現有 angular 項目中以某種方式遺漏了 karma.config。

所以我手動添加了它並嘗試使用命令ng test運行ng test

運行時顯示以下錯誤。

[./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

我注意到應用程序中有兩個 tsconfig.json,第一個位於項目根文件夾和內容下

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

第二個存在於 src 文件夾中,內容是

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

我試圖在任何這些文件中使用 include 來添加 src/polyfills.ts 但沒有運氣。

誰能指導如何解決這個問題?

角度版本 - 6

我發現tsconfig.spec.json沒有polyfills.ts 所以我把它添加如下,問題就解決了

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

這篇文章: TypeScript 編譯中缺少模塊構建失敗 ts。 請確保它通過“文件”或“包含”屬性在您的 tsconfig 中幫助我驗證 tsconfig.json、tsconfig.app.json 和 tsconfig.spec.json 的內容。

暫無
暫無

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

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