Skip to content

Commit 19257f6

Browse files
authored
Merge pull request #271 from evanw/dynamic-require
Fix WebPack compatibility by using dynamic require
2 parents 4cba532 + e92f20c commit 19257f6

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

source-map-support.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ try {
1414

1515
var bufferFrom = require('buffer-from');
1616

17+
/**
18+
* Requires a module which is protected against bundler minification.
19+
*
20+
* @param {NodeModule} mod
21+
* @param {string} request
22+
*/
23+
function dynamicRequire(mod, request) {
24+
return mod.require(request);
25+
}
26+
1727
// Only install once if called multiple times
1828
var errorFormatterInstalled = false;
1929
var uncaughtShimInstalled = false;
@@ -565,9 +575,8 @@ exports.install = function(options) {
565575
// Worker threads. Workers pass the error to the main thread as an event,
566576
// rather than printing something to stderr and exiting.
567577
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');
578+
// We need to use `dynamicRequire` because `require` on it's own will be optimized by WebPack/Browserify.
579+
var worker_threads = dynamicRequire(module, 'worker_threads');
571580
if (worker_threads.isMainThread === false) {
572581
installHandler = false;
573582
}

0 commit comments

Comments
 (0)