developit / developit/workerize-loader

ReferenceError: regeneratorRuntime is not defined

Open
#71 4 comments 0 reactions 0 assignees View on GitHub
documentation question
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:
![image](https://user-images.githubusercontent.com/5295397/61249686-31709a80-a756-11e9-813d-1448ffaf1b33.png)

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.