question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Node 12 process.removeListener is not a function

See original GitHub issue

Prerequisites

  • Checked that your issue hasn’t already been filed by cross-referencing issues with the faq label
  • Checked next-gen ES issues and syntax problems by using the same environment and/or transpiler configuration without Mocha to ensure it isn’t just a feature that actually isn’t supported in the environment in question or a bug in your code.
  • ‘Smoke tested’ the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, your usage of Mocha, or Mocha itself
  • Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with: node node_modules/.bin/mocha --version(Local) and mocha --version(Global). We recommend that you not install Mocha globally.

Description

Running unit tests with "mocha": "6.1.4", on my repository along with Node v12.0.0 results in error process.removeListener is not a function

This error does not occur with Node v10.15.1

Steps to Reproduce

I suspect the error will occur any time you run unit tests with mocha along with Node 12, but here’s a way:

  1. Clone my repository: git clone https://github.com/whyboris/karma-helpful-reporter.git

  2. Install Node v12.0.0 (I’m using nvm to switch back between versions easily)

  3. Then npm run test and see the error. Note that the error does not occur on Node v10.

Expected behavior: [What you expect to happen] No error with Node 12

Actual behavior: [What actually happens]

    process.removeListener('uncaughtException', uncaught);
            ^

TypeError: process.removeListener is not a function

Reproduces how often: [What percentage of the time does it reproduce?] Every time

Versions

“mocha”: “6.1.4”, Node v12.0.0

  • The output of mocha --version and node node_modules/.bin/mocha --version: 6.1.4
  • The output of node --version: v12.0.0
  • Your operating system
    • name and version: Mac OS 10.14.6
    • architecture (32 or 64-bit): 64bit
  • Your shell (e.g., bash, zsh, PowerShell, cmd): zsh
  • Your browser and version (if running browser tests): n/a
  • Any third-party Mocha-related modules (and their versions): n/a (?)
  • Any code transpiler (e.g., TypeScript, CoffeeScript, Babel) being used (and its version): TypeScript (?)

Additional Information

Full log:

  1) "after each" hook
/Users/byakubchik/Desktop/temp/karma-helpful-reporter/node_modules/mocha/lib/runner.js:917
    process.removeListener('uncaughtException', uncaught);
            ^

TypeError: process.removeListener is not a function
    at Runner.<anonymous> (/Users/byakubchik/Desktop/temp/karma-helpful-reporter/node_modules/mocha/lib/runner.js:917:13)
    at Runner.emit (events.js:196:13)
    at /Users/byakubchik/Desktop/temp/karma-helpful-reporter/node_modules/mocha/lib/runner.js:903:12
    at done (/Users/byakubchik/Desktop/temp/karma-helpful-reporter/node_modules/mocha/lib/runner.js:761:7)
    at next (/Users/byakubchik/Desktop/temp/karma-helpful-reporter/node_modules/mocha/lib/runner.js:728:16)
    at done (/Users/byakubchik/Desktop/temp/karma-helpful-reporter/node_modules/mocha/lib/runner.js:761:7)
    at next (/Users/byakubchik/Desktop/temp/karma-helpful-reporter/node_modules/mocha/lib/runner.js:732:14)
    at done (/Users/byakubchik/Desktop/temp/karma-helpful-reporter/node_modules/mocha/lib/runner.js:761:7)
    at next (/Users/byakubchik/Desktop/temp/karma-helpful-reporter/node_modules/mocha/lib/runner.js:732:14)
    at done (/Users/byakubchik/Desktop/temp/karma-helpful-reporter/node_modules/mocha/lib/runner.js:761:7)
    at next (/Users/byakubchik/Desktop/temp/karma-helpful-reporter/node_modules/mocha/lib/runner.js:732:14)
    at done (/Users/byakubchik/Desktop/temp/karma-helpful-reporter/node_modules/mocha/lib/runner.js:761:7)
    at next (/Users/byakubchik/Desktop/temp/karma-helpful-reporter/node_modules/mocha/lib/runner.js:732:14)
    at Runner.hookErr (/Users/byakubchik/Desktop/temp/karma-helpful-reporter/node_modules/mocha/lib/runner.js:575:7)
    at Runner.uncaught (/Users/byakubchik/Desktop/temp/karma-helpful-reporter/node_modules/mocha/lib/runner.js:857:19)
    at process.uncaught (/Users/byakubchik/Desktop/temp/karma-helpful-reporter/node_modules/mocha/lib/runner.js:887:10)
    at process.emit (events.js:196:13)
    at process._fatalException (internal/process/execution.js:146:25)

Node documentation for removeListener: https://nodejs.org/api/events.html#events_event_removelistener [edit] - documentation should be here, thank you @plroebuck : https://nodejs.org/api/events.html#events_emitter_removelistener_eventname_listener

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:17 (11 by maintainers)

github_iconTop GitHub Comments

3reactions
Muntercommented, Nov 4, 2019

I can recreate the error by cloning git@github.com:whyboris/karma-helpful-reporter, creating a clean install on node 12.13.0 and running the test suite:

$ npm t

> karma-helpful-reporter@0.3.4 test /Users/pbm/git/karma-helpful-reporter
> nyc mocha



[REMOVED SUCCESSFUL TESTS OUTPUT]


  105 passing (1s)

  1) "after each" hook
/Users/pbm/git/karma-helpful-reporter/node_modules/mocha/lib/runner.js:917
    process.removeListener('uncaughtException', uncaught);
            ^

TypeError: process.removeListener is not a function
    at Runner.<anonymous> (/Users/pbm/git/karma-helpful-reporter/node_modules/mocha/lib/runner.js:917:13)
    at Runner.emit (events.js:210:5)
    at /Users/pbm/git/karma-helpful-reporter/node_modules/mocha/lib/runner.js:903:12
    at done (/Users/pbm/git/karma-helpful-reporter/node_modules/mocha/lib/runner.js:761:7)
    at next (/Users/pbm/git/karma-helpful-reporter/node_modules/mocha/lib/runner.js:728:16)
    at done (/Users/pbm/git/karma-helpful-reporter/node_modules/mocha/lib/runner.js:761:7)
    at next (/Users/pbm/git/karma-helpful-reporter/node_modules/mocha/lib/runner.js:732:14)
    at done (/Users/pbm/git/karma-helpful-reporter/node_modules/mocha/lib/runner.js:761:7)
    at next (/Users/pbm/git/karma-helpful-reporter/node_modules/mocha/lib/runner.js:732:14)
    at done (/Users/pbm/git/karma-helpful-reporter/node_modules/mocha/lib/runner.js:761:7)
    at next (/Users/pbm/git/karma-helpful-reporter/node_modules/mocha/lib/runner.js:732:14)
    at done (/Users/pbm/git/karma-helpful-reporter/node_modules/mocha/lib/runner.js:761:7)
    at next (/Users/pbm/git/karma-helpful-reporter/node_modules/mocha/lib/runner.js:732:14)
    at Runner.hookErr (/Users/pbm/git/karma-helpful-reporter/node_modules/mocha/lib/runner.js:575:7)
    at Runner.uncaught (/Users/pbm/git/karma-helpful-reporter/node_modules/mocha/lib/runner.js:857:19)
    at process.uncaught (/Users/pbm/git/karma-helpful-reporter/node_modules/mocha/lib/runner.js:887:10)
    at process.emit (events.js:210:5)
    at processEmit [as emit] (/Users/pbm/git/karma-helpful-reporter/node_modules/signal-exit/index.js:155:32)
    at process._fatalException (internal/process/execution.js:150:25)
2reactions
mikeebowencommented, Oct 31, 2019

I’m also seeing exactly the same issue with mocha tests in node 12.12.0 and the screenshot above is what I also see.

Read more comments on GitHub >

github_iconTop Results From Across the Web

node removeListener does not work - Stack Overflow
trying to remove listener with this code:
Read more >
Events | Node.js v19.3.0 Documentation
Awaiting multiple events emitted on process. ... removeListener(type, listener) ... When the EventEmitter object emits an event, all of the functions ...
Read more >
".matchMedia(...).removeEventListener is not a function ...
In modern browsers, the MediaQueryList object inherits from the EventTarget object, which makes the removeEventListener method available on the ...
Read more >
MediaQueryList.removeListener() - Web APIs - MDN Web Docs
The removeListener() method of the MediaQueryList interface removes a listener from the MediaQueryListener.
Read more >
mocha/mocha.js - chromium/src/third_party - Git at Google
not listening for removeListener, no need to emit. if (!events. ... based off https://github.com/defunctzombie/node-process/blob/master/browser.js. function ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found