Support Workers using CommonJS syntax
See original GitHub issueFeature request
What is the expected behavior? For Webpack to support workers using CommonJS syntax when targeting node.
The following works in Node:
const { Worker } = require("worker_threads");
const path = require("path");
const worker = new Worker(path.join(__dirname, "./worker.js"));
But is not currently transformed by Webpack.
What is motivation or use case for adding/changing the behavior? https://github.com/pinojs/pino/issues/1465
Essentially looking for a way that pino could support bundling it’s workers without needing a specialized plugin for each existing bundler.
P.S. It could be useful for libraries starting workers dynamically to be able to get the URL/filename of a transformed worker module bundle instead of just immediately starting it or receiving a custom class that starts it.
How should this be implemented in your opinion? Recognize that as an additional syntax and transform it appropriately in a similar way the existing worker syntax is transformed.
Are you willing to work on this yourself? yes (But I’m not familiar with Webpack internals, and not sure where to start learning them in the docs).
Issue Analytics
- State:
- Created a year ago
- Comments:10 (8 by maintainers)

Top Related StackOverflow Question
please use esm syntax as suggested with
new URL(...). cjs syntax very unlikely will be supported…Yes, I think small and clear API will be great here