AbortController statement causes Uncaught Error

I'm trying to pull a library into my worker that has this toplevel declaration:
const neverSignal = new AbortController().signal;
const neverSignal = new AbortController().signal;
When I run wrangler dev --experimental-local or wrangler publish, I'm met with the following error:
service core:user:: Uncaught Error: Some functionality, such as asynchronous I/O, timeouts, and generating random values, can only be performed while handling a request.
at index.js:24:19
service core:user:: Uncaught Error: Some functionality, such as asynchronous I/O, timeouts, and generating random values, can only be performed while handling a request.
at index.js:24:19
(where the location points to the new AbortSignal line). I've noticed this only happens on real deployment and and with --experimental-local, not with --local.
I'm fairly new to the js/ts/workers world so am looking to understand if this is expected? From looking at the library code [1] I don't see a way to not trigger this. I could reach out to the library authors and ask if they can adapt the library for workers but besides [2] I did not find any good limitations regarding the use of abortcontroller in workers that would cause this error (and allow them to test for continued support) [1] https://github.com/bufbuild/connect-es/blob/c18d298d026a769b4075aac3d03f78bcb6b60e11/packages/connect/src/protocol/universal-handler.ts#L142-L159 [2] https://developers.cloudflare.com/workers/runtime-apis/web-standards#abortcontroller-and-abortsignal
0 Replies
No replies yetBe the first to reply to this messageJoin