{"id":22294,"library":"rollup-plugin-workers","title":"rollup-plugin-workers","description":"A Rollup plugin that adds code splitting for JavaScript module Workers (Web Workers, Shared Workers, Service Workers) and Worklets (AudioWorklet, PaintWorklet, LayoutWorklet, AnimationWorklet). Current stable version: 2.1.1. Works with Rollup >= 1.11.0. It transforms Worker/Worklet import patterns into separate output chunks, enabling dynamic code splitting for multithreaded applications. Unlike generic worker plugins, this plugin specifically targets module-type workers and supports ES module format in workers. Does not include a module loader; users must handle chunk loading.","status":"active","version":"2.1.1","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/johanholmerin/rollup-plugin-workers","tags":["javascript"],"install":[{"cmd":"npm install rollup-plugin-workers","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-workers","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-workers","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency; plugin only works with Rollup >= 1.11.0","package":"rollup","optional":false}],"imports":[{"note":"Plugin is ESM-only; CommonJS require will fail unless using dynamic import.","wrong":"const worker = require('rollup-plugin-workers')","symbol":"default","correct":"import worker from 'rollup-plugin-workers'"},{"note":"Default export only; named export 'worker' is not available.","wrong":null,"symbol":"worker","correct":"import { default as worker } from 'rollup-plugin-workers'"},{"note":"The function is the default export; using named import will result in undefined.","wrong":"import { worker } from 'rollup-plugin-workers'","symbol":"Rollup plugin usage","correct":"import worker from 'rollup-plugin-workers';\n\nexport default {\n  plugins: [worker()]\n}"}],"quickstart":{"code":"import worker from 'rollup-plugin-workers';\n\nexport default {\n  input: 'main.js',\n  output: {\n    dir: 'dist',\n    format: 'esm'\n  },\n  plugins: [worker()]\n};","lang":"javascript","description":"Demonstrates basic Rollup configuration with the workers plugin to enable code splitting for module workers."},"warnings":[{"fix":"Upgrade Rollup to version 1.11.0 or higher.","message":"Requires Rollup >= 1.11.0; older versions will fail to load the plugin.","severity":"breaking","affected_versions":"<=1.10.x"},{"fix":"Provide a module loader or use a bundler that supports automatic chunk loading (e.g., Vite).","message":"Plugin does not include a module loader. You must handle loading of split chunks manually in the browser.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure worklet registration uses the pattern obj.worklet.addModule, where worklet is one of: AudioWorklet, PaintWorklet, LayoutWorklet, AnimationWorklet.","message":"Worklet calls must exactly follow format '*.*Worklet.addModule(...)'. Arbitrary function calls won't be recognized.","severity":"gotcha","affected_versions":"all"},{"fix":"Always pass { type: 'module' } as second argument to Worker/SharedWorker constructors, and for ServiceWorker use { type: 'module' } in register().","message":"Workers must be of type 'module' and use the correct constructor signature (e.g., new Worker('./worker.js', { type: 'module' })).","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Install the package: npm install -D rollup-plugin-workers. Use import syntax instead of require.","cause":"Package not installed or CommonJS require used in ESM context.","error":"Error: Cannot find module 'rollup-plugin-workers'"},{"fix":"Change import to default import: import worker from 'rollup-plugin-workers'.","cause":"Named import used instead of default import.","error":"TypeError: worker is not a function"},{"fix":"Upgrade Rollup to version >= 1.11.0.","cause":"Rollup version is below 1.11.0.","error":"Error: The Rollup version is not supported by rollup-plugin-workers"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}