Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fifty-keys-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"workflow": patch
---

Remove `dirs` option from `workflows` config object in `withWorkflow()` and related documentation
40 changes: 1 addition & 39 deletions docs/content/docs/api-reference/workflow-next/with-workflow.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,42 +49,4 @@ export default async function config(
}
return nextConfig;
}
```

## Configuration

The second argument to `withWorkflow` accepts the following options:

### `workflows.dirs`

Directories to scan for workflows and steps. If provided, this completely overrides the defaults.

- **Type:** `string[]`
- **Default:** `['pages', 'app', 'src/pages', 'src/app']`

```typescript title="next.config.ts" lineNumbers
import { withWorkflow } from "workflow/next";
import type { NextConfig } from "next";

const nextConfig: NextConfig = {};

export default withWorkflow(nextConfig, {
workflows: {
dirs: ['workflows', 'src/workflows'], // [!code highlight]
},
});
```

### `workflows.local.port`

Port for the local workflow server during development.

- **Type:** `number`
- **Default:** Uses the `PORT` environment variable

### `workflows.local.dataDir`

Directory for storing local workflow data during development.

- **Type:** `string`
- **Default:** `'.next/workflow-data'`
```
39 changes: 0 additions & 39 deletions docs/content/docs/getting-started/next.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -257,45 +257,6 @@ Check the [Deploying](/docs/deploying) section to learn how your workflows can b

## Troubleshooting

### Out of Memory (OOM) during build

When using `withWorkflow()` in a large Next.js application, the "Discovering workflow directives" phase may consume excessive memory, causing builds to fail with OOM errors on standard build machines (e.g., 16 GB RAM).

**Solution:** Use the `workflows.dirs` option to limit the directories scanned for workflow directives. By default, `withWorkflow` scans `['pages', 'app', 'src/pages', 'src/app']`, which in large applications can include thousands of files.

If your workflows are located in a specific directory, configure `dirs` to only scan that directory:

```typescript title="next.config.ts" lineNumbers
import { withWorkflow } from "workflow/next";
import type { NextConfig } from "next";

const nextConfig: NextConfig = {};

export default withWorkflow(nextConfig, {
workflows: {
// Only scan the workflows directory instead of the entire app
dirs: ['workflows'], // [!code highlight]
},
});
```

If you need workflows in both app routes and a dedicated directory:

```typescript title="next.config.ts" lineNumbers
import { withWorkflow } from "workflow/next";
import type { NextConfig } from "next";

const nextConfig: NextConfig = {};

export default withWorkflow(nextConfig, {
workflows: {
dirs: ['app/api', 'workflows'], // [!code highlight]
},
});
```

This significantly reduces memory usage and build times by avoiding scanning unrelated application code.

### Next.js 16.1+ compatibility

If you see this error when upgrading to Next.js 16.1 or later:
Expand Down
16 changes: 2 additions & 14 deletions packages/next/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ import semver from 'semver';
import { getNextBuilder } from './builder.js';
import { maybeInvalidateCacheOnSwcChange } from './swc-cache.js';

/**
* Default directories to scan for workflows and steps.
* These are the standard Next.js app directories.
*/
const DEFAULT_WORKFLOW_DIRS = ['pages', 'app', 'src/pages', 'src/app'];

export function withWorkflow(
nextConfigOrFn:
| NextConfig
Expand All @@ -25,13 +19,6 @@ export function withWorkflow(
port?: number;
dataDir?: string;
};
/**
* Directories to scan for workflows and steps.
* If provided, this completely overrides the defaults.
*
* @default ['pages', 'app', 'src/pages', 'src/app']
*/
dirs?: string[];
};
} = {}
) {
Expand Down Expand Up @@ -149,7 +136,8 @@ export function withWorkflow(
const NextBuilder = await getNextBuilder();
const workflowBuilder = new NextBuilder({
watch: shouldWatch,
dirs: workflows?.dirs ?? DEFAULT_WORKFLOW_DIRS,
// discover workflows from pages/app entries
dirs: ['pages', 'app', 'src/pages', 'src/app'],
workingDir: process.cwd(),
buildTarget: 'next',
workflowsBundlePath: '', // not used in base
Expand Down
Loading