From 1db97ff2c9387d6f93cfebbdaf6b09537a9cc7bd Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sun, 19 Apr 2020 03:36:57 +0200 Subject: [PATCH 1/2] Fix Node.js Worker support by not shimming uncaughtException MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: https://github.com/evanw/node-source-map-support/issues/268 Fixes: https://github.com/TypeStrong/ts-node/issues/945 --- source-map-support.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/source-map-support.js b/source-map-support.js index 1561cee..4d6f9e1 100644 --- a/source-map-support.js +++ b/source-map-support.js @@ -561,6 +561,17 @@ exports.install = function(options) { var installHandler = 'handleUncaughtExceptions' in options ? options.handleUncaughtExceptions : true; + // Do not override 'uncaughtException' with our own handler in Node.js + // Worker threads. Workers pass the error to the main thread as an event, + // rather than printing something to stderr and exiting. + try { + // Don't let browserify try to resolve this require(), it's pointless + // and breaks the build process. + var worker_threads = require('worker_' + 'threads'); + if (worker_threads.isMainThread === false) + installHandler = false; + } catch(e) {} + // Provide the option to not install the uncaught exception handler. This is // to support other uncaught exception handlers (in test frameworks, for // example). If this handler is not installed and there are no other uncaught From 59b442f716e2859484f9febc18a9842202886a6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20Unneb=C3=A4ck?= Date: Sun, 19 Apr 2020 12:36:47 +0100 Subject: [PATCH 2/2] Use braces around if body --- source-map-support.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source-map-support.js b/source-map-support.js index 4d6f9e1..40be2b1 100644 --- a/source-map-support.js +++ b/source-map-support.js @@ -568,8 +568,9 @@ exports.install = function(options) { // Don't let browserify try to resolve this require(), it's pointless // and breaks the build process. var worker_threads = require('worker_' + 'threads'); - if (worker_threads.isMainThread === false) + if (worker_threads.isMainThread === false) { installHandler = false; + } } catch(e) {} // Provide the option to not install the uncaught exception handler. This is