Registry / web-framework / workerize-loader

workerize-loader

JSON →
library2.0.2jsnpmunverified

A Webpack loader that moves a module and its dependencies into a Web Worker, automatically reflecting exported functions as asynchronous proxies. Version 2.0.2 is current, supporting Webpack 5. It bundles a tiny RPC implementation, supports synchronous and async worker functions, and works with async/await. Key differentiators: no separate worker file needed, automatically wraps exports as async proxies, and allows instantiable Worker decorators.

npm install workerize-loader
INSTALL
IMPORT
SIG · WORKERIZE-LOADER
W
workerize-loader
web-frameworkjavascriptv2.0.2
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–223 runs
build_error
glibc
node 18–223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

worker (default import)
✓ import worker from 'workerize-loader!./worker'
✗ const worker = require('workerize-loader!./worker')
CommonJS require may cause issues with webpack loader resolution; always use ESM import syntax.
Worker instance
✓ let instance = worker()
✗ let instance = new worker()
Both work, but the loader returns a function that returns a Worker instance; 'new' is optional.
Inline worker option
✓ import worker from 'workerize-loader?inline!./worker'
Inline option creates a blob URL; useful for CSP restrictions.

Demonstrates basic usage: exports a synchronous function from a worker module, imports via loader, and calls it asynchronously.

// worker.js export function expensive(time) { let start = Date.now(), count = 0; while (Date.now() - start < time) count++; return count; } // index.js import worker from 'workerize-loader!./worker'; let instance = worker(); instance.expensive(1000).then(count => { console.log(`Ran ${count} loops`); });
Debug
Known issues
gotchaUsing CommonJS require instead of import will not trigger webpack loader.
fix
Use ES6 import syntax: import worker from 'workerize-loader!./worker'
affects: >=1.0
gotchaBabel with commonJS transform will break workerize-loader's export detection.
fix
Disable commonJS transform in Babel configuration (e.g., set modules: false).
affects: >=1.0
breakingVersion 2.0.0 dropped support for Webpack 4; only Webpack 5 is supported.
fix
Upgrade to webpack 5 or stay on workerize-loader 1.x.
affects: >=2.0
gotchaWorker files must use ESM export syntax; default exports are not supported.
fix
Use named exports in worker file: export function foo() {}
affects: >=1.0
gotchaIf output.globalObject is set to 'window', HMR may break.
fix
Set output.globalObject to 'this' or remove custom globalObject configuration.
affects: >=1.0.4
Errors
Common errors & fixes
Error: workerize-loader: no exports found in module
Worker module has only default exports or no named exports.
fix
Ensure worker module uses named exports: export function myFunc() {}
Module parse failed: Unexpected token (1:0) You may need an appropriate loader to handle this file type.
Webpack is trying to parse the worker file without workerize-loader applied.
fix
Use correct import syntax: import worker from 'workerize-loader!./worker' or configure loader in webpack.config.
The 'require' function is used in a way in which dependencies cannot be statically extracted
Using dynamic require in worker module.
fix
Use static import statements only in worker module files.
workerize-loader: 'name' option must be a string
Invalid option passed to loader.
fix
Use the correct option format: { loader: 'workerize-loader', options: { name: '[name].[contenthash:8]' } }
Upgrade
Version history
2.0.2latest on npm
Audit
Dependencies
webpackrequiredpeer dependency required for loader functionality
Agent activity
41 hits · last 30 days
node
32
Bingbot
1
OpenAI (training)
1
Resources
workerize-loader — npm install workerize-loader · libregistry