Skip to content

"start" receives invalid workflow function — "use workflow" directive not transformed (Next.js 16 + Turbopack + Vercel World) #1478

@jonio87

Description

@jonio87

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

  1. Static imports (top-level import { start } from "workflow/api") — same error
  2. Dynamic imports (await import("workflow/api")) — same error
  3. Webpack build (NEXT_TURBOPACK=0 npx next build) — same error
  4. Cleared .next cache + .workflow-data — same error
  5. next start (production mode) — same error
  6. Different worlds — Vercel World, Local World, Postgres World — all same error
  7. 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 regression
  • d72c822 ("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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions