developit / developit/workerize-loader
ReferenceError: regeneratorRuntime is not defined
- Dominant language
- JavaScript
- Stars
- 2.3k
- Forks
- 85
- PR merge metrics
- No merged PRs in 30d
Description
I'm trying to use this library with Babel and TypeScript, but I'm getting a weird error.
```ts
// queue.worker.ts
import { TrackData } from "modules/track/types"
import { shuffleArray } from "common/lang/array/helpers/shuffleArray"
export async function getShuffledTracks(tracks: TrackData[], active: number) {
return shuffleArray(tracks).sort((track) => (track.id === active ? -1 : 0))
}
```
```ts
// somewhere.ts
import * as QueueWorker from "../queue.worker"
const worker = (QueueWorker as any)() as typeof QueueWorker
// somewhere in the file
await worker.getShuffledTracks(...)
```
Then, when the function is called, I get this error:

This is what the config for the loader looks like:
```js
const workerRule = {
test: /\.worker\.ts$/,
use: [
"workerize-loader",
{
loader: "babel-loader",
options: {
presets: [
[
"@babel/env",
{
modules: false,
},
],
],
},
},
],
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the failure from queue.worker.ts and somewhere.ts using the shown workerize-loader and babel-loader configuration. Inspect how the worker bundle handles the async function and Babel runtime, then verify that calling getShuffledTracks no longer raises ReferenceError: regeneratorRuntime is not defined.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- babel, javascript, typescript, webpack
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100