惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - Franky
T
Tailwind CSS Blog
Microsoft Azure Blog
Microsoft Azure Blog
The Cloudflare Blog
博客园 - 叶小钗
N
Netflix TechBlog - Medium
罗磊的独立博客
量子位
MyScale Blog
MyScale Blog
A
About on SuperTechFans
Blog — PlanetScale
Blog — PlanetScale
V
Visual Studio Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
GbyAI
GbyAI
B
Blog
腾讯CDC
爱范儿
爱范儿
Recent Announcements
Recent Announcements
有赞技术团队
有赞技术团队
F
Fortinet All Blogs
雷峰网
雷峰网
G
Google Developers Blog
Google DeepMind News
Google DeepMind News

Workflow SDK Documentation

Patterns for Defining Tools Human-in-the-Loop Building Durable AI Agents Queueing User Messages Resumable Streams Sleep, Suspense, and Scheduling Streaming Updates from Tools API Reference Workflow Globals Changelog Resilient run start Cookbook Building a World Deploying Astro Express Fastify Hono Getting Started NestJS Next.js Nitro Nuxt Python SvelteKit Vite corrupted-event-log fetch-in-workflow hook-conflict Errors
withWorkflow
2026-05-31 · via Workflow SDK Documentation

Configure webpack/turbopack to transform workflow directives in Next.js.

Configures webpack/turbopack loaders to transform workflow code ("use step"/"use workflow" directives)

To enable "use step" and "use workflow" directives while developing locally or deploying to production, wrap your nextConfig with withWorkflow.

import { withWorkflow } from "workflow/next"; 
import type { NextConfig } from "next";
 
const nextConfig: NextConfig = {
  // … rest of your Next.js config
};

// not required but allows configuring workflow options
const workflowConfig = {} 

export default withWorkflow(nextConfig, workflowConfig); 

If a package in serverExternalPackages contains workflow code ("use step", "use workflow", or serialization classes), withWorkflow() automatically removes it from serverExternalPackages for the current build and prints a warning. This ensures the package still gets transformed by the Workflow compiler. Remove that package from serverExternalPackages in your next.config to silence the warning.

Monorepos and Workspace Imports

By default, Next.js detects the correct workspace root automatically. If your Next.js app lives in a subdirectory such as apps/web and workspace resolution is not working correctly, you can set outputFileTracingRoot as a workaround:

import { resolve } from "node:path";
import type { NextConfig } from "next";
import { withWorkflow } from "workflow/next";

const nextConfig: NextConfig = {
  outputFileTracingRoot: resolve(process.cwd(), "../.."),
};

export default withWorkflow(nextConfig);

Use the smallest directory that contains every workspace package imported by your workflows. If your app already lives at the repository root, you do not need to set outputFileTracingRoot.

withWorkflow accepts an optional second argument to configure the Next.js integration.

import type { NextConfig } from "next";
import { withWorkflow } from "workflow/next";

const nextConfig: NextConfig = {};

export default withWorkflow(nextConfig, {
  workflows: {
    lazyDiscovery: true,
    local: {
      port: 4000,
    },
    sourcemap: false,
  },
});
OptionTypeDefaultDescription
workflows.lazyDiscoverybooleanfalseWhen true, defers workflow discovery until files are requested instead of scanning eagerly at startup. Useful for large projects where startup time matters.
workflows.local.portnumberOverrides the PORT environment variable for local development. Has no effect when deployed to Vercel.
workflows.sourcemapboolean | 'inline' | 'linked' | 'external' | 'both''inline'Controls source maps on generated workflow bundles. See Source maps below.

Source maps

The step bundle and intermediate workflow bundle default to 'inline' source maps so that stack traces from step errors and workflow VM errors point at your source files. The sourcemap option lets you change that:

ValueBehavior
true / 'inline'Base64-encode the source map and append it to the bundle (default).
'linked'Write a separate .map file and add a sourceMappingURL comment.
'external'Write a separate .map file without the comment.
'both'Emit both inline and external source maps.
falseOmit source maps entirely.

Setting sourcemap: false is the main escape hatch for users hitting the Vercel 250MB function size limit — it drops the inline source map from every bundle and also skips the source-map-support runtime shim on the Vercel step function. The tradeoff is that workflow VM stack traces will reference generated code (e.g. evalmachine.<anonymous>) rather than your source files.

Setting sourcemap explicitly affects all generated bundles (steps, workflows, webhook). The legacy WORKFLOW_EMIT_SOURCEMAPS_FOR_DEBUGGING=1 environment variable is narrower — it only toggles source maps on the final workflow wrapper and webhook bundle (which default to off). It continues to work, but new code should use the sourcemap option or the WORKFLOW_SOURCEMAP environment variable instead.

The option can also be set via the WORKFLOW_SOURCEMAP environment variable, which accepts the same values plus '0' / '1' as aliases for false / true. Precedence is: explicit config > WORKFLOW_SOURCEMAP > per-bundle default.

The workflows.local options only affect local development. When deployed to Vercel, the runtime ignores local settings and uses the Vercel world automatically.

If you are exporting a function in your next.config you will need to ensure you call the function returned from withWorkflow.

import { NextConfig } from "next";
import { withWorkflow } from "workflow/next";
import createNextIntlPlugin from "next-intl/plugin";

const withNextIntl = createNextIntlPlugin();

export default async function config(
  phase: string,
  ctx: {
    defaultConfig: NextConfig
  }
): Promise<NextConfig> {
  let nextConfig: NextConfig | typeof config = {};

  for (const configModifier of [withNextIntl, withWorkflow]) {
    nextConfig = configModifier(nextConfig);

    if (typeof nextConfig === "function") {
      nextConfig = await nextConfig(phase, ctx);
    }
  }
  return nextConfig;
}