Skip to content

Commit bdba50e

Browse files
committed
Fix Node.js Worker support by not shimming uncaughtException
Node.js Worker threads don’t handle `uncaughtException` the same way that the main thread does. The shim does not apply/make sense here, but breaks error handling support in unexpected ways instead. Fixes: evanw/node-source-map-support#268 Fixes: TypeStrong/ts-node#945
1 parent db386c8 commit bdba50e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

source-map-support.js

+11
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,17 @@ exports.install = function(options) {
561561
var installHandler = 'handleUncaughtExceptions' in options ?
562562
options.handleUncaughtExceptions : true;
563563

564+
// Do not override 'uncaughtException' with our own handler in Node.js
565+
// Worker threads. Workers pass the error to the main thread as an event,
566+
// rather than printing something to stderr and exiting.
567+
try {
568+
// Don't let browserify try to resolve this require(), it's pointless
569+
// and breaks the build process.
570+
var worker_threads = require('worker_' + 'threads');
571+
if (worker_threads.isMainThread === false)
572+
installHandler = false;
573+
} catch(e) {}
574+
564575
// Provide the option to not install the uncaught exception handler. This is
565576
// to support other uncaught exception handlers (in test frameworks, for
566577
// example). If this handler is not installed and there are no other uncaught

0 commit comments

Comments
 (0)