Skip to content

[bug] waitUntil error in 1.4.0 in dev #41

@saltytostitos

Description

@saltytostitos

Description

Getting a weird error while using in development.

 ERROR  Error while capturing another error Illegal invocation                                                                                                                                                                                                                                                                            10:30:44 AM

    at waitUntil (node_modules/.pnpm/wrangler@4.62.0_bufferutil@4.1.0_utf-8-validate@6.0.6/node_modules/wrangler/wrangler-dist/cli.js:296999:17)
    at callDrainHook (.nuxt/dev/index.mjs:5967:5)
    at .nuxt/dev/index.mjs:6016:7
    at process.processTicksAndRejections (node:internal/process/task_queues:103:5)
    at async Promise.all (index 0)

Extracting and calling it directly is losing its this context.

Suggestion:

  // extract to variable first

  const cfContext = event.context.cloudflare?.context
  if (cfContext && typeof cfContext.waitUntil === 'function') cfContext.waitUntil(drainPromise)
  else if (event.context.waitUntil && typeof event.context.waitUntil === 'function')  event.context.waitUntil(drainPromise)

const waitUntil = event.context.cloudflare?.context?.waitUntil

This fixes the problem for me.
✔️ Tested in dev
✔️ Tested in prod (Nuxt in Cloudflare Workers)

Reproduction

Operating system Linux 6.18.7-arch1-1
CPU 12th Gen Intel(R) Core(TM) i9-12900K (24 cores)
Node.js version v24.11.1
nuxt/cli version 3.32.0
Package manager pnpm@10.28.1
Nuxt version 4.3.0
Nitro version 2.13.1
Builder vite@8.0.0-beta.11
Config app, auth, compatibilityDate, css, devtools, evlog, experimental, fonts, hub, icon, imports, mdc, modules, nitro, posthogConfig, routeRules, runtimeConfig, sourcemap, telemetry, typescript, uiPro, vite
Modules nuxt-auth-utils@0.5.28, @nuxthub/core@0.10.6, @nuxt/image@2.0.0, @nuxt/fonts@0.12.1, @nuxt/scripts@0.13.2, @nuxt/ui@4.4.0, @nuxtjs/mdc@0.20.0, motion-v/nuxt@1.10.2, nuxt-charts@2.1.1, evlog/nuxt@1.4.0, @posthog/nuxt@1.5.26

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions