cloudflare / cloudflare/workers-sdk
vite-plugin tail forwarding throws on a BigInt while the miniflare copy handles it
- Dominant language
- TypeScript
- Stars
- 4.5k
- Forks
- 1.5k
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 187
Description
### What version of `wrangler` are you using?
`main` (packages/vite-plugin-cloudflare)
### What operating system and version are you using?
macOS
### Describe the Bug
`packages/vite-plugin-cloudflare/src/workers/vite-proxy-worker/index.ts` forwards tail events by serializing them to JSON, but its replacer only handles `Date`:
```ts
override tail(events: TraceItem[]) {
return this.env.ENTRY_USER_WORKER.tail(
JSON.parse(JSON.stringify(events, tailEventsReplacer), tailEventsReviver)
);
}
function tailEventsReplacer(_: string, value: unknown) {
if (value instanceof Date) {
return { [serializedDate]: value.toISOString() };
}
return value;
}
```
`JSON.stringify` throws on a `bigint`, and that call isn't wrapped in a `try`/`catch`, so a tail event carrying one takes out the forwarding path:
```
TypeError: Do not know how to serialize a BigInt
```
The equivalent replacer in miniflare (`packages/miniflare/src/workers/core/dev-registry-proxy-shared.worker.ts`) does handle it, tagging the value with `___serialized_bigint___` and restoring it in the reviver. So the two copies of what looks like the same helper disagree: the miniflare one survives a bigint, the vite one throws.
### Please provide a link to a minimal reproduction
The divergence is visible without a dashboard, running each replacer over the same input:
```js
const events = [{ outcome: "ok", cpuTime: 5n }];
JSON.stringify(events, viteReplacer);
// TypeError: Do not know how to serialize a BigInt
JSON.stringify(events, miniflareReplacer);
// [{"outcome":"ok","cpuTime":{"___serialized_bigint___":"5"}}]
```
I haven't established which real `TraceItem` fields can arrive as a `bigint` in practice, which is why I'm raising this rather than sending a patch — if none currently do, this is latent rather than live.
### Please provide any relevant error logs
```
TypeError: Do not know how to serialize a BigInt
at JSON.stringify ()
```
### Note
I noticed this while working on #15181, which fixes a separate `Date` round-trip bug in both copies of this helper. I deliberately kept that PR to the `Date` issue and left this alone, since adding a `bigint` arm to the vite copy also needs a matching reviver and is a different change. Happy to send it if you'd like it fixed.
Contributor guide
Research direction
Start in packages/vite-plugin-cloudflare/src/workers/vite-proxy-worker/index.ts, comparing tailEventsReplacer and tailEventsReviver with the equivalent helpers in packages/miniflare/src/workers/core/dev-registry-proxy-shared.worker.ts. Run the minimal reproduction using an event containing cpuTime: 5n and verify that the Vite proxy preserves the bigint through serialization and revival without changing the existing Date behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 76/100