Karma: Running karma results in a warning: a promise was created, but was not returned from it

Created on 30 Jun 2018  路  16Comments  路  Source: karma-runner/karma

Expected behaviour

When using karma start, no warning is logged.

Actual behaviour

This warning is logged: (node:16432) Warning: a promise was created in a handler at \node_modules\karma\lib\server.js:122:24 but was not returned from it, see http://goo.gl/rRqMUw

Environment Details

  • Karma version (output of karma --version): 2.0.4
  • Relevant part of your karma.config.js file: _(none)_

Steps to reproduce the behaviour

  1. Install karma 2.0.4 and run karma start
investigation windows

Most helpful comment

This warning was emitted by bluebird library and Karma >= 5.0.0 does not use bluebird anymore. Please let me know if you still experience this warning in the latest Karma and I'll re-open this issue to investigate further.

All 16 comments

I used the steps in https://karma-runner.github.io/latest/intro/installation.html to install and run karma. I do not see this error message.

I am running nodejs v8.9.4 on macosx.

I assume this is windows only issue.

Realistically I think you need to investigate this issue if you want it fixed.

Can you edit your lib/server.js and change line 122 from:

      this._injector.invoke(this._start, this)

to

     console.log('calling invoke');
     return this._injector.invoke(this._start, this)

Thanks for the quick response.

I've tried your suggestion, but no luck:

calling invoke
(node:664) Warning: a promise was created in a handler at \node_modules\karma\lib\server.js:123:31 but was not returned from it, see http://goo.gl/rRqMUw

I've also changed line 286 in lib/cli.js from new Server(config).start() to new Server(config).start().then(() => console.log('started!')), but to no avail. I don't see the 'started!' message in the console either. Any more ideas?

We are seeing a similar error on node 10.4.1 in a Docker container:

(node:47) Warning: a promise was created in a handler at /code/node_modules/karma/lib/server.js:122:24 but was not returned from it, see http://goo.gl/rRqMUw
    at Function.Promise.cast (/code/node_modules/bluebird/js/release/promise.js:196:13)

The tests are running fine though.

Ah that makes sense. @johnjbarton could you try again on node 10?

The Container base is Debian Slim by the way and the host machine MacOS. I've started the tests on my host with node 10.4.1 as well now and get the same warning.

Same issue here: Node.js 10.8.0, Karma 2.0.5, on Ubuntu 18.04.1.

(node:25924) Warning: a promise was created in a handler at /repo/lcov.js/node_modules/karma/lib/server.js:123:24 but was not returned from it, see http://goo.gl/rRqMUw
    at Function.Promise.cast (/repo/lcov.js/node_modules/bluebird/js/release/promise.js:196:13)

If I set the NODE_NO_WARNINGS environment variable to 1, the warning is not silenced. Instead I get a verbose stack trace:

Warning: a promise was created in a handler at /repo/lcov.js/node_modules/karma/lib/server.js:123:24 but was not returned from it, see http://goo.gl/rRqMUw
    at Function.Promise.cast (/repo/lcov.js/node_modules/bluebird/js/release/promise.js:196:13)
    at runCallback (timers.js:693:18)
    at tryOnImmediate (timers.js:664:5)
    at processImmediate (timers.js:646:5)
From previous event:
    at createFilesPromise (/repo/lcov.js/node_modules/karma/lib/web-server.js:36:28)
    at Array.invoke (/repo/lcov.js/node_modules/di/lib/injector.js:75:15)
    at get (/repo/lcov.js/node_modules/di/lib/injector.js:48:43)
    at /repo/lcov.js/node_modules/di/lib/injector.js:71:14
    at Array.map (<anonymous>)
    at Injector.invoke (/repo/lcov.js/node_modules/di/lib/injector.js:70:31)
    at createWebServer (/repo/lcov.js/node_modules/karma/lib/web-server.js:69:24)
    at Array.invoke (/repo/lcov.js/node_modules/di/lib/injector.js:75:15)
    at Injector.get (/repo/lcov.js/node_modules/di/lib/injector.js:48:43)
    at Server._start (/repo/lcov.js/node_modules/karma/lib/server.js:146:38)
    at Injector.invoke (/repo/lcov.js/node_modules/di/lib/injector.js:75:15)
    at Promise.all.then.then (/repo/lcov.js/node_modules/karma/lib/server.js:123:24)
From previous event:
    at Server.start (/repo/lcov.js/node_modules/karma/lib/server.js:120:8)
    at Object.exports.run (/repo/lcov.js/node_modules/karma/lib/cli.js:286:26)
    at Object.<anonymous> (/repo/lcov.js/node_modules/karma/bin/karma:3:23)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:266:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)

EDIT: replacing this._injector.invoke(this._start, this) by return this._injector.invoke(this._start, this) in lib/server.js did not change anything (i.e. the warning is aways there).

The code involved is

function createFilesPromise (emitter, fileList) {
  const filesPromise = new common.PromiseContainer()

  // Set an empty list of files to avoid race issues with
  // file_list_modified not having been emitted yet
  filesPromise.set(Promise.resolve(fileList.files))

  emitter.on('file_list_modified', (files) => filesPromise.set(Promise.resolve(files)))

  return filesPromise
}

I don't know how to convince Bluebird that there is no problem here.

The issue does not reproduce in any of our tests. If someone can write a unit test or small example we can fix it.

Returning a null or a promise seems to remove the warning:

  start () {
    const config = this.get('config')
    return Promise.all([
      BundleUtils.bundleResourceIfNotExist('client/main.js', 'static/karma.js'),
      BundleUtils.bundleResourceIfNotExist('context/main.js', 'static/context.js')
    ])
      .then(() => {return NetUtils.bindAvailablePort(config.port, config.listenAddress)})
      .then((boundServer) => {
        config.port = boundServer.address().port
        this._boundServer = boundServer
        this._injector.invoke(this._start, this)
        return null
      })
      .catch(this.dieOnError.bind(this))
  }

or

  start () {
    const config = this.get('config')
    return Promise.all([
      BundleUtils.bundleResourceIfNotExist('client/main.js', 'static/karma.js'),
      BundleUtils.bundleResourceIfNotExist('context/main.js', 'static/context.js')
    ])
      .then(() => {return NetUtils.bindAvailablePort(config.port, config.listenAddress)})
      .then((boundServer) => {
          return new Promise(() => {
            config.port = boundServer.address().port
            this._boundServer = boundServer
            this._injector.invoke(this._start, this)
          })
      })
      .catch(this.dieOnError.bind(this))
  }

Any update on this issue?

We are using the latest Angular CLI 7.0.5, and it provides the karma setup that results in this warning:

(node:4108) Warning: a promise was created in a handler at
...\node_modules\karma\lib\server.js:125:24 but was not returned from it

Running on Windows 10, with Node.js v11.1.0

Still no test that shows this issue and therefore could be used to show it is solved.

same issue here:
windows7 node 10+
(node:6636) Warning: a promise was created in a handler at node_modules\karma\lib\server.js:125:24 but was not returned from it, see http://goo.gl/rRqMUw
at Function.Promise.cast (node_modules\bluebird\js\release\promise.js:196:13)
15 11 2018 23:45:13.211:INFO [karma-server]: Karma v3.1.1 server started at http://0.0.0.0:9889/

This is happening for me as well, but only in a Gitlab CI build using a docker container, and not when running in my local Ubuntu directly. NOTE: I haven't yet tried to reproduce this locally via my docker container.

karma 3.1.1
npm info using [email protected]
npm info using [email protected]

Docker container it based on:

FROM cypress/browsers

which is based on:

node:8-slim debian

And I extend the container by installing build-essentials, updating npm to 6.4.0 and installing a couple global npm dependencies. Karma is installed at build time as part of the project's package.json, and not part of this dockerfile.

log output, I assume the warning about Tapable.plugin is not related, but I'm including it anyhow:

> npx karma start karma.ci.conf.js --single-run

WEBPACK build in env development with HOSTNAME undefined; clientConfig: {"NODE_ENV":"\"development\"","HOSTNAME":"\"\"","SERVERURL":"\"\"","DEBUG_MODE":false}
(node:21) Warning: a promise was created in a handler at ./node_modules/karma/lib/server.js:125:24 but was not returned from it, see http://goo.gl/rRqMUw
    at Function.Promise.cast (./node_modules/bluebird/js/release/promise.js:196:13)
(node:21) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead

Karma 3.1.3, Windows 10, Node.js 11.4.0 :

(node:22112) Warning: a promise was created in a handler at C:\Repo\js\cookies.js\node_modules\karma\lib\server.js:127:24 but was not returned from it, see http://goo.gl/rRqMUw
    at Function.Promise.cast (C:\Repo\js\cookies.js\node_modules\bluebird\js\release\promise.js:196:13)

On my side, whatever OS (Ubuntu 18.x or Windows 10) or Node.js version (10.x, 11.x) or Karma (2.x or 3.x) I use , I always get this warning. Pretty annoying, but the tests pass anyway.

Karma 3.1.4, macOS 10.14.2, Node 8.10.0

(node:22497) Warning: a promise was created in a handler at .../node_modules/karma/lib/server.js:127:24 but was not returned from it, see http://goo.gl/rRqMUw
    at Function.Promise.cast (.../node_modules/bluebird/js/release/promise.js:196:13)

Can confirm adding return null silences the warning...

 start() {
   const config = this.get("config");
   return Promise.all([
     BundleUtils.bundleResourceIfNotExist("client/main.js", "static/karma.js"),
     BundleUtils.bundleResourceIfNotExist(
       "context/main.js",
       "static/context.js"
     )
   ])
     .then(() => NetUtils.bindAvailablePort(config.port, config.listenAddress))
     .then(boundServer => {
       config.port = boundServer.address().port;
       this._boundServer = boundServer;
       this._injector.invoke(this._start, this);
+      return null;
     })
     .catch(err => {
       this.dieOnError(`Server start failed on port ${config.port}: ${err}`);
     });
 }

This warning was emitted by bluebird library and Karma >= 5.0.0 does not use bluebird anymore. Please let me know if you still experience this warning in the latest Karma and I'll re-open this issue to investigate further.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

IgorMinar picture IgorMinar  路  5Comments

mgol picture mgol  路  3Comments

VinishaDsouza picture VinishaDsouza  路  3Comments

wellyshen picture wellyshen  路  4Comments

HerrDerb picture HerrDerb  路  5Comments