developit / developit/workerize-loader

ReferenceError: regeneratorRuntime is not defined

未关闭
#71 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
documentation question
主要语言
JavaScript
星标
2.3k
派生
85
PR 合并指标
30 天内没有已合并 PR

描述

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,
},
],
],
},
},
],
}
```

贡献指南

这个仓库没有索引到贡献指南

调研方向

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.

由索引模型根据 Issue 内容生成。

评估

技术栈
babel, javascript, typescript, webpack
领域
build-system, tooling
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。