Search code examples
javascriptnode.jspromisev8

Finding source of unhandled promise rejection: TypeError: Chaining cycle detected for promise


I'm trying to find the source of an unhandled rejection from a Promise in Node.js

I've tried upgrading to Node version 12, using the --async-stack-traces option, and listening for them using:

process.on("unhandledRejection",( reason, promise ) => {
  console.log(reason);
  console.log(promise);
});

But I still don't see any helpful stack trace to help me find the culprit!

UnhandledPromiseRejectionWarning: TypeError: Chaining cycle detected for promise #<Promise>
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:89675) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 11)

Running Node v10.10.0


Solution

  • thanks for all the suggestions. I've tried once more by upgrading to the latest Node 12.14.1 and was finally able to get it to show the stack trace:

    I used node --async-stack-traces myScript.js in conjunction with:

    process.on('unhandledRejection', (reason, p) => {
      console.log(reason);
    });
    

    And it tracked down the error.