{"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,"search_vec":"'2.0.2':26 '5':31 'allow':62 'async':41,59 'async/await':47 'asynchron':23 'automat':18,55 'bundl':33 'current':28 'decor':65 'depend':13 'differenti':49 'export':20,57 'file':53 'function':21,43 'implement':37 'instanti':63 'javascript':66 'key':48 'loader':3,6,68 'modul':10 'move':8 'need':54 'proxi':24,60 'reflect':19 'rpc':36 'separ':51 'support':29,38 'synchron':39 'thread':72 'tini':35 'version':25 'web':16,70 'webpack':5,30,67 'work':45 'worker':2,17,42,52,64,69,71,73 'workerize-load':1 'wrap':56","created_at":"2026-04-25T11:25:24.161638+00:00","updated_at":"2026-04-25T11:25:24.161638+00:00","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,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/developit/workerize-loader","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/workerize-loader","openapi_spec":null,"status_page":null,"smithery":null,"categories":["web-framework","devops","http-networking","serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-24","install_tag":null}}