mocha: Node 12 process.removeListener is not a function
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) andmocha --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:
-
Clone my repository:
git clone https://github.com/whyboris/karma-helpful-reporter.git
-
Install Node v12.0.0 (I’m using
nvm
to switch back between versions easily) -
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
andnode 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
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 17 (11 by maintainers)
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: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.@whyboris I’m closing this issue. I think it’s your turn now to improve your testing code. Mocha needs the uncaught error handler to process uncaught exception. Overwriting the
process
object is a severe error in your code. It’s your turn.@rgroothuijsen thank you for your confirmation. 👍 @whyboris can I close this issue?
Have you updated your Node version? Which version do you use now?
Node documentation link should be to this.
Does this occur with the built-in reporters, or just your custom one?