Registry / http-networking / webworkify-webpack

webworkify-webpack

JSON →
library2.1.5jsnpmunverified

Launches a web worker at runtime from webpack's bundled modules, including only the used dependencies. Version 2.1.5 is stable, uses webpack's API to avoid hacks from v1, and has no eval restrictions. It is an alternative to worker-loader and target: 'webworker', allowing a single bundle for both main thread and worker contexts. Requires webpack and uses require.resolve.

npm install webworkify-webpack
INSTALL
IMPORT
SIG · WEBWORKIFY-WEBPACK
W
webworkify-webpack
http-networkingjavascriptv2.1.5
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

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

work
import work from 'webworkify-webpack'
const work = require('webworkify-webpack')
ESM default export; CommonJS require() also works but is not recommended for consistency.
work
let w = work(require.resolve('./worker.js'))
let w = work('./worker.js')
Must use require.resolve() to get the module path, not a plain string literal.
work
let w = work(require.resolve('./worker.js'), { bare: true })
let w = work(require.resolve('./worker.js'), { bare: true }, options)
Options is the second argument, not third.

Creates a web worker from worker.js using webworkify-webpack, sends a message, and logs the response.

// main.js import work from 'webworkify-webpack'; let w = work(require.resolve('./worker.js')); w.addEventListener('message', event => { console.log('Worker said: ', event.data); }); w.postMessage('Hello worker'); // worker.js module.exports = function() { self.addEventListener('message', event => { self.postMessage(event.data + ' back at ya!'); }); };
Debug
Known issues
gotchaMust use require.resolve() with the worker module path, not a string literal.
fix
Use require.resolve('./worker.js') instead of './worker.js'.
affects: >=2.0.0
gotchaCode outside module.exports in the worker file runs in both main thread and worker.
fix
Place only the worker logic inside module.exports; avoid heavy computation in outer scope.
affects: *
gotchaAnonymous functions as module.exports may cause issues (v1 had problems; v2 claims to fix).
fix
Upgrade to v2 or use named function exports.
affects: <2.0.0
gotchaCannot use devtools like HMR with webworkify-webpack; it's runtime-based.
fix
Use worker-loader or target: 'webworker' if HMR is needed.
affects: *
deprecatedThe package is not actively maintained; last release in 2019.
fix
Consider using worker-loader or @kayak/webpack-workers for modern webpack versions.
affects: *
Errors
Common errors & fixes
Error: Cannot find module './worker.js'
Using a string literal instead of require.resolve().
fix
Change work('./worker.js') to work(require.resolve('./worker.js')).
Uncaught ReferenceError: require is not defined
Running in an environment without CommonJS require (e.g., pure ESM or browser without webpack).
fix
Bundle with webpack and use ES import: import work from 'webworkify-webpack'.
TypeError: Cannot read property 'apply' of undefined
Worker module's module.exports is not a function.
fix
Ensure the worker file exports a function via module.exports = function() { ... }.
Error: webworkify-webpack: require.resolve is not a function
Using webworkify-webpack outside of a webpack bundle where require.resolve is not available.
fix
Only use this library within a webpack-bundled application.
Upgrade
Version history
2.1.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
16 hits · last 30 days
node
14
OpenAI (training)
1
Resources
webworkify-webpack — npm install webworkify-webpack · libregistry