{"id":20868,"library":"workerize-loader","title":"workerize-loader","description":"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.","status":"active","version":"2.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/developit/workerize-loader","tags":["javascript","webpack","loader","worker","web worker","thread","workerize"],"install":[{"cmd":"npm install workerize-loader","lang":"bash","label":"npm"},{"cmd":"yarn add workerize-loader","lang":"bash","label":"yarn"},{"cmd":"pnpm add workerize-loader","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency required for loader functionality","package":"webpack","optional":false}],"imports":[{"note":"CommonJS require may cause issues with webpack loader resolution; always use ESM import syntax.","wrong":"const worker = require('workerize-loader!./worker')","symbol":"worker (default import)","correct":"import worker from 'workerize-loader!./worker'"},{"note":"Both work, but the loader returns a function that returns a Worker instance; 'new' is optional.","wrong":"let instance = new worker()","symbol":"Worker instance","correct":"let instance = worker()"},{"note":"Inline option creates a blob URL; useful for CSP restrictions.","wrong":"","symbol":"Inline worker option","correct":"import worker from 'workerize-loader?inline!./worker'"}],"quickstart":{"code":"// worker.js\nexport function expensive(time) {\n    let start = Date.now(),\n        count = 0;\n    while (Date.now() - start < time) count++;\n    return count;\n}\n\n// index.js\nimport worker from 'workerize-loader!./worker';\n\nlet instance = worker();\n\ninstance.expensive(1000).then(count => {\n    console.log(`Ran ${count} loops`);\n});\n","lang":"javascript","description":"Demonstrates basic usage: exports a synchronous function from a worker module, imports via loader, and calls it asynchronously."},"warnings":[{"fix":"Use ES6 import syntax: import worker from 'workerize-loader!./worker'","message":"Using CommonJS require instead of import will not trigger webpack loader.","severity":"gotcha","affected_versions":">=1.0"},{"fix":"Disable commonJS transform in Babel configuration (e.g., set modules: false).","message":"Babel with commonJS transform will break workerize-loader's export detection.","severity":"gotcha","affected_versions":">=1.0"},{"fix":"Upgrade to webpack 5 or stay on workerize-loader 1.x.","message":"Version 2.0.0 dropped support for Webpack 4; only Webpack 5 is supported.","severity":"breaking","affected_versions":">=2.0"},{"fix":"Use named exports in worker file: export function foo() {}","message":"Worker files must use ESM export syntax; default exports are not supported.","severity":"gotcha","affected_versions":">=1.0"},{"fix":"Set output.globalObject to 'this' or remove custom globalObject configuration.","message":"If output.globalObject is set to 'window', HMR may break.","severity":"gotcha","affected_versions":">=1.0.4"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Ensure worker module uses named exports: export function myFunc() {}","cause":"Worker module has only default exports or no named exports.","error":"Error: workerize-loader: no exports found in module"},{"fix":"Use correct import syntax: import worker from 'workerize-loader!./worker' or configure loader in webpack.config.","cause":"Webpack is trying to parse the worker file without workerize-loader applied.","error":"Module parse failed: Unexpected token (1:0) You may need an appropriate loader to handle this file type."},{"fix":"Use static import statements only in worker module files.","cause":"Using dynamic require in worker module.","error":"The 'require' function is used in a way in which dependencies cannot be statically extracted"},{"fix":"Use the correct option format: { loader: 'workerize-loader', options: { name: '[name].[contenthash:8]' } }","cause":"Invalid option passed to loader.","error":"workerize-loader: 'name' option must be a string"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}