ERROR in ./src/polyfills.ts Module not found: Error: Can't resolve 'zone.js/dist/zone'

ERROR in ./src/polyfills.ts Module not found: Error: Can't resolve 'zone.js/dist/zone'

我有一个 angular 8,它使用 karma/jasmine 到 运行 一些单元测试。我可以通过执行以下命令 ng test 来 运行 测试,但我收到以下错误:

ERROR in ./src/polyfills.ts Module not found: Error: Can't resolve 'zone.js/dist/zone' in 'C:\PrjNET\Elevation3\FW.00\Project\Framework\Development\Client\ElevationJS\shell\src' resolve 'zone.js/dist/zone' in 'C:\PrjNET\Elevation3\FW.00\Project\Framework\Development\Client\ElevationJS\shell\src'

有人知道怎么解决吗?

我发现我在 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"
  ]
}

错误消失了!

我用这个命令在我的项目中修复了它:

npm install zone.js@0.11.3 --save

我在使用 zone.js@0.8.29 时收到此错误。

zone-testing 仅存在于 0.8.19。尝试安装最新版本。使用:

npm i zone.js

以上命令适用于我的情况。