./src/polyfills.ts中的错误找不到模块:错误:无法解析“ zone.js / dist / zone”

时间:2019-07-12 09:00:39

标签: angular typescript unit-testing jasmine karma-runner

我有一个8号角,它使用业力/茉莉花来运行一些单元测试。我可以通过执行以下命令ng test来运行测试,但出现以下错误:

  ./src/polyfills.ts中的

ERROR找不到模块:错误:无法解决   'zone.js / dist / zone'在   'C:\ PrjNET \ Elevation3 \ FW \ 4.00 \ Project \ Framework \ Development \ Client \ ElevationJS \ shell \ src'   解决'zone.js / dist / zone'在   'C:\ PrjNET \ Elevation3 \ FW \ 4.00 \ Project \ Framework \ Development \ Client \ ElevationJS \ shell \ src'

有人知道如何解决吗?

2 个答案:

答案 0 :(得分:1)

我使用以下命令在项目中修复了该问题:

npm install zone.js@0.11.3 --save

我使用zone.js@0.8.29遇到此错误。

答案 1 :(得分:0)

我发现我在tsconfig.spec.json上的测试配置错误。所以我改变了:

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

对此:

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

错误消失了!