angular – 无法将浏览器连接到Karma服务器(永久页面加载)

我正在使用IntelliJ启动Karma.一切看起来都不错,新的Chrome窗口弹出,但它会永远保持加载状态.

业力日志:

17 07 2018 13:29:01.754:INFO [karma]: Karma v1.7.1 server started at http://0.0.0.0:9877/
17 07 2018 13:29:01.758:INFO [launcher]: Launching browser Chrome with unlimited concurrency
17 07 2018 13:29:01.773:INFO [launcher]: Starting browser Chrome

 10% building modules 1/3 modules 2 active …ts\rafa-components-lib\src\polyfills.ts
 10% building modules 2/3 modules 1 active …ts\rafa-components-lib\src\polyfills.ts
 75% basic chunk optimization EnsureChunkConditionsPlugin
 75% basic chunk optimization RemoveParentModulesPlugin
 88% hashing
 90% additional chunk assets processing
 92% after chunk asset optimization SourceMapDevToolPlugin main.js generate SourceMap
Waiting for a captured browser... To capture a browser open http://localhost:9877/

访问localhost:9877会导致永久加载.有时它按预期工作(业力开始和浏览器连接)但它有点随机.

也许有人知道发生了什么?

Karma配置:

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular-devkit/build-angular/plugins/karma')
    ],
    client: {
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    coverageIstanbulReporter: {
      dir: require('path').join(__dirname, '../coverage'),
      reports: ['html', 'lcovonly'],
      fixWebpackSourcePaths: true
    },
    reporters: ['progress', 'kjhtml'],
    port: 9877,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false
  });
};

新的浏览器窗口:
enter image description here

建立连接:
enter image description here

最佳答案
我在Webstorm中遇到了同样的问题.

我的测试中有编译问题,在我的情况下,它在node_modules / rxjs / Observable.d.ts(1,15)中是错误的:错误TS2307:找不到模块’rxjs-compat / Observable’..

在Webstorm控制台中,仅在第三次无法捕获浏览器后才显示错误.运行测试时,您将立即看到编译错误.解决之后,测试在Webstorm中运行得很好.

转载注明原文:angular – 无法将浏览器连接到Karma服务器(永久页面加载) - 代码日志