-
Notifications
You must be signed in to change notification settings - Fork 221
"start" receives invalid workflow function — "use workflow" directive not transformed (Next.js 16 + Turbopack + Vercel World) #1478
Description
Summary
start() throws 'start' received an invalid workflow function even though the function has a "use workflow" directive. The build correctly discovers the directive and generates the manifest (14 steps, 1 workflow), but at runtime the function is not recognized as a valid workflow.
Environment
- workflow:
4.2.0-beta.71 - Next.js:
16.1.5(Turbopack — default bundler) - Node: 22.12.0
- World: Vercel World (Pro plan) — also reproduced with Local World
- Platform: macOS (local) + Vercel serverless (deployed)
Configuration
// next.config.ts
import { withWorkflow } from "workflow/next";
const nextConfig = { /* ... */ } as NextConfig;
export default withWorkflow(nextConfig);// instrumentation.ts
export async function register() {
// No-op — Vercel World is auto-managed
}Workflow definition
// lib/workflows/callback-pipeline.ts
import { sleep, createWebhook } from "workflow"
async function fetchLead(leadId: string) {
"use step"
// ...
}
// ... 13 more "use step" functions
export async function callbackPipeline(
leadId: string,
phone: string,
scoreTier: string,
leadTier: string,
) {
"use workflow"
// ... orchestration using steps + sleep + createWebhook
}API route (caller)
// app/api/leads/route.ts
import { start } from "workflow/api"
import { callbackPipeline } from "@/lib/workflows/callback-pipeline"
// Inside POST handler:
await start(callbackPipeline, [leadId, phone, scoreTier, leadTier])Build output (looks correct)
Discovering workflow directives 1920ms
Created steps bundle 109ms
Created intermediate workflow bundle 67ms
Creating webhook route
Created manifest with 14 steps, 1 workflow, and 0 classes 12ms
Generated routes exist:
├ ƒ /.well-known/workflow/v1/flow
├ ƒ /.well-known/workflow/v1/step
├ ƒ /.well-known/workflow/v1/webhook/[token]
Runtime error
[WDK] Callback pipeline start failed (non-fatal): 'start' received an invalid workflow function.
Ensure the Workflow Development Kit is configured correctly and the function includes a
'use workflow' directive.
Learn more: https://useworkflow.dev/err/start-invalid-workflow-function
What I've tried
- Static imports (top-level
import { start } from "workflow/api") — same error - Dynamic imports (
await import("workflow/api")) — same error - Webpack build (
NEXT_TURBOPACK=0 npx next build) — same error - Cleared
.nextcache +.workflow-data— same error next start(production mode) — same error- Different worlds — Vercel World, Local World, Postgres World — all same error
- Verified
"use workflow"directive is present in the exported function
Suspected cause
The withWorkflow() async config function runs at build time and generates the manifest + routes, but the SWC transform that converts "use workflow" annotated functions into manifest-referenced stubs does not execute during the Turbopack build pipeline. The original function reaches start() untransformed, so start() doesn't recognize it.
This may be related to:
a2c0c7e("Seed lazy workflow file discovery in NextJS. Require workflow definitions to be in manifest for Vercel environments") — the manifest requirement may have introduced a regressiond72c822("Fix bug where the SWC compiler prunes step-only imports in the client-mode transformation") — possibly related SWC transform issue
Workaround
Using a callback orchestrator pattern (direct function calls via an event bus) instead of WDK start(). The WDK config remains in place and is ready to re-enable once this is resolved.