Errors
DEFER_SCOPE_REQUIRED
defer() was called without a Crux execution scope or ambient host binding.
What failed
defer() was called where no Crux primitive scope or ambient-capable host
binding was active.
Why
Crux must know which execution boundary owns the work. Without a scope or host binding, it cannot establish drain timing, retention, limits, or cancellation. It throws instead of silently dropping the registration.
Fix
Run crux setup --check for the exact host-specific remediation, then choose
the smallest matching rung:
- Move the call inside a Crux agent, adapter, tool, Safety session, or other defer-capable primitive.
- On Next or Vercel, add the platform binding to
config({ host }). - On Workers, use a per-request boundary with the current
ctx. - Add a strict wrapper when handler outcome or response commitment must be part of the same invocation.
import { config } from "@use-crux/core";
import { next } from "@use-crux/next";
export default config({ host: next() });Inside replayable flow execution, use flow.defer() instead.
See Host support and Troubleshooting.