← 回首頁
Cloudflare Workers

ctx.waitUntil is not defined

TypeError: Cannot read properties of undefined (reading 'waitUntil')

🔍 為什麼會發生

你在 fetch 里调用了 ctx.waitUntil(),但 fetch 函数签名里没传第三个参数 ctx。Worker 的 fetch 是 `fetch(request, env, ctx)`,ctx 必须显式接收。

🛠️ 怎麼修

  1. 把 async fetch(request, env) 改成 async fetch(request, env, ctx)
  2. TypeScript 项目里用 async fetch(request: Request, env: Env, ctx: ExecutionContext)
  3. 如果你不需要后台任务,直接去掉 ctx.waitUntil,改成 await
相關工具: 加密貨幣手續費計算器 · VRAM 計算器
看更多加密貨幣工具

本站為技術速查,內容僅供參考。錯誤訊息以官方文件為準。