worker-loader causes webpack to run out of memory when dynamic requires are used

The following works without issues:

// main.js
const MyWorker = require('worker!./my-worker');

// my-worker.js
const myModule = require('my-module');
self.onmessage = e => { /* do stuff */ };

However as soon as you start introducing dynamic requires, webpack compilation will enter an infinite loop and eventually run out of memory:

// main.js
const MyWorker = require('worker!./my-worker');

// my-worker.js
self.onmessage = e => {
    const myModule = require(e.data.modulePath);
    /* do stuff */
};

Am I missing sth obvious, or is it a legitimate bug?

Author: Fantashit

1 thought on “worker-loader causes webpack to run out of memory when dynamic requires are used

Comments are closed.