Node.js Uncaught TypeError: callback is not a function in process.nextTick

I get the following error. This clearly comes from the callback passed to process.nextTick. Given the stack trace is practically unusable, how do I debug this? What happens behind the scenes and how can I resolve this in a larger project?

TypeError: callback is not a function
    at nextTickCallbackWith0Args (node.js:420:9)
    at process._tickDomainCallback (node.js:390:13)

NB Older versions of Node had a different implementation process.nextTickand spit out the next stack trace.

Uncaught TypeError: undefined is not a function
    at process._tickCallback (node.js:415:13)
+4
source share
1 answer

Node.js tick callback , , process.nextTick, , , , , .

:

// this will print "hi!", followed by "hello there"
process.nextTick(function() {
  console.log('hello there');
});
console.log('hi!');

:

// this will just print "hi!", and an error will be thrown later on
process.nextTick(undefined);
console.log('hi!');

, .

1: longjohn

, , .

longjohn ( npm), require - . , :

TypeError: Cannot read property 'apply' of undefined
    at nextTickCallbackWith0Args (node.js:420:9)
    at process._tickCallback (node.js:349:13)
    at Function.Module.runMain (module.js:443:11)
    at startup (node.js:139:18)
    at node.js:968:3
---------------------------------------------
    at Object.<anonymous> (.../example.js:3:9)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:139:18)
    at node.js:968:3

, , , , process.nextTick undefined, .

javascript , process.nextTick ( ), , - nextTick:

var nextTick = process.nextTick;

process.nextTick = function(callback) {
  if (typeof callback !== 'function') {
    console.trace(typeof callback + ' is not a function');
  }
  return nextTick.apply(process, arguments);
};

. , , - process.nextTick. , process, - , , , , . (: , , .)

Trace: undefined is not a function
    at process.nextTick (.../example.js:5:13)
    at Object.<anonymous> (.../example.js:10:9)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:139:18)
    at node.js:968:3

, , , .

_tickCallback node.js ( ).

+5

All Articles