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.

TypeError: setTimeout(...).unref is not a function

See original GitHub issue

Hi! I have some problems with using stoppable on node v8.7.0

here are couple of stack traces:

    TypeError: setTimeout(...).unref is not a function

      at Immediate.setImmediate [as _onImmediate] (node_modules/stoppable/lib/stoppable.js:33:39)
      at runCallback (timers.js:785:20)
      at tryOnImmediate (timers.js:747:5)
      at processImmediate [as _immediateCallback] (timers.js:718:5)
    TypeError: setTimeout(...).unref is not a function

      at Immediate.setImmediate [as _onImmediate] (node_modules/stoppable/lib/stoppable.js:33:39)
      at runCallback (timers.js:785:20)
      at tryOnImmediate (timers.js:747:5)
      at processImmediate (timers.js:718:5)
      at _combinedTickCallback (internal/process/next_tick.js:131:7)
      at process._tickCallback (internal/process/next_tick.js:180:9)

I use babel, jest, flow and lots of other things, so it’s hard to say is it problem of stoppable or not.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

8reactions
ronkorvingcommented, Nov 12, 2018

I’ve seen things like this happen when run from Jest, which runs in Browser-mode by default, which means it replaces setTimeout and does not return an object with an unref function on it. Perhaps you’re also running in some sort of browser emulation mode?

0reactions
glassercommented, Feb 23, 2021

Could the call to unref be replaced by a call to clearTimeout in the server.close callback?

The point of unref is that it lets the Node process terminate if it’s the only remaining thing. But that process isn’t going to terminate until the server is closed (unless you’ve also unreffed the server, I guess?), so the first time it could possibly be relevant is after the server.close callback is done. So we might as well just call clearTimeout ourselves at that point, no?

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: setTimeout(...).unref is not a function
in your jest.config.js , make sure there's this: module.exports = { testEnvironment: 'node', };. See more about this option on the ...
Read more >
Calling Timeout.unref() With setTimeout() Does Not Appear ...
This tells Node. js to exit out of the process (in this demo) if the timeout is the only pending operation.
Read more >
Timer Mocks
The native timer functions (i.e., setTimeout(), setInterval(), ... At this point in time, the callback should not have been called yet
Read more >
Process | Node.js v18 API
The listener callback function is invoked with the value of process. ... If the parameter passed in is not a tuple Array ,...
Read more >
Node.js – Timeout-ref() & Timeout-unref() method
timeout.unref(). This method will tell the timeout object that the Node.js event loop does not need to be active anymore. If there is...
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