waitUntil illigal invocation

I was planning to use waitUntil, but as soon it runs the worker die with this error:
[mf:err] TypeError: Illegal invocation
at Object.fetch (/path/src/index.js:59:5)
at __facade_modules_fetch__ (/tmp/tmp-778150-oye4YPdtwnN2/middleware-loader.entry.ts:46:16)
at __facade_invokeChain__ (/path/node_modules/wrangler/templates/middleware/common.ts:53:9)
at Object.next (/path/node_modules/wrangler/templates/middleware/common.ts:50:11)
at jsonError (/path/node_modules/wrangler/templates/middleware/middleware-miniflare3-json-error.ts:22:30)
at __facade_invokeChain__ (/path/node_modules/wrangler/templates/middleware/common.ts:53:9)
at __facade_invoke__ (/path/node_modules/wrangler/templates/middleware/common.ts:63:9)
at Object.fetch (/tmp/tmp-778150-oye4YPdtwnN2/middleware-loader.entry.ts:114:11)
[mf:err] TypeError: Illegal invocation
at Object.fetch (/path/src/index.js:59:5)
at __facade_modules_fetch__ (/tmp/tmp-778150-oye4YPdtwnN2/middleware-loader.entry.ts:46:16)
at __facade_invokeChain__ (/path/node_modules/wrangler/templates/middleware/common.ts:53:9)
at Object.next (/path/node_modules/wrangler/templates/middleware/common.ts:50:11)
at jsonError (/path/node_modules/wrangler/templates/middleware/middleware-miniflare3-json-error.ts:22:30)
at __facade_invokeChain__ (/path/node_modules/wrangler/templates/middleware/common.ts:53:9)
at __facade_invoke__ (/path/node_modules/wrangler/templates/middleware/common.ts:63:9)
at Object.fetch (/tmp/tmp-778150-oye4YPdtwnN2/middleware-loader.entry.ts:114:11)
wrangler version 3.2.0 and 3.3.0. In this example I'm just running a resolve, running anything else the promise will run but the worker will die anyway
export default {
fetch: async (request, env, { waitUntil }) => {
waitUntil(Promise.resolve())
return new Response('hello')
}
}
export default {
fetch: async (request, env, { waitUntil }) => {
waitUntil(Promise.resolve())
return new Response('hello')
}
}
am I doing something wrong?
2 Replies
o0th
o0thOP2y ago
Ok I don't know if I'm missing something, but this works
export default {
fetch: async (request, env, ctx) => {
ctx.waitUntil(Promise.resolve())
return new Response('hello')
}
}
export default {
fetch: async (request, env, ctx) => {
ctx.waitUntil(Promise.resolve())
return new Response('hello')
}
}
sexnine
sexnine12mo ago
for anyone else stumbling upon this issue in the future (like me :3), i had a similar issue using trpc in sveltekit where i was adding the function to the trpc context and it was failing with Illegal invocation: assigning a function that calls waitUntil instead solved this issue for me:
export async function createContext(event: RequestEvent) {
return {
event,
- waitUntil: event.platform.context.waitUntil,
+ waitUntil: (promise: Promise<any>) => {
+ event.platform.context.waitUntil(promise);
+ },
};
}
export async function createContext(event: RequestEvent) {
return {
event,
- waitUntil: event.platform.context.waitUntil,
+ waitUntil: (promise: Promise<any>) => {
+ event.platform.context.waitUntil(promise);
+ },
};
}
Want results from more Discord servers?
Add your server