workflow 4.2.0-beta.76 → 4.2.0-beta.77
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/api-reference/workflow-ai/durable-agent.mdx +86 -1
- package/docs/api-reference/workflow-api/get-world.mdx +51 -0
- package/docs/api-reference/workflow-api/start.mdx +5 -0
- package/docs/api-reference/workflow-next/with-workflow.mdx +51 -0
- package/docs/changelog/meta.json +1 -1
- package/docs/changelog/resilient-start.mdx +327 -0
- package/docs/deploying/building-a-world.mdx +16 -6
- package/docs/deploying/index.mdx +2 -2
- package/docs/deploying/world/vercel-world.mdx +30 -1
- package/docs/errors/hook-conflict.mdx +1 -1
- package/docs/errors/node-js-module-in-workflow.mdx +1 -1
- package/docs/errors/start-invalid-workflow-function.mdx +83 -58
- package/docs/foundations/starting-workflows.mdx +1 -1
- package/docs/foundations/streaming.mdx +1 -1
- package/docs/getting-started/astro.mdx +17 -0
- package/docs/getting-started/express.mdx +17 -0
- package/docs/getting-started/fastify.mdx +17 -0
- package/docs/getting-started/hono.mdx +17 -0
- package/docs/getting-started/nestjs.mdx +83 -5
- package/docs/getting-started/next.mdx +16 -1
- package/docs/getting-started/nitro.mdx +17 -0
- package/docs/getting-started/nuxt.mdx +17 -0
- package/docs/getting-started/sveltekit.mdx +17 -0
- package/docs/getting-started/vite.mdx +17 -0
- package/docs/how-it-works/encryption.mdx +39 -2
- package/docs/how-it-works/event-sourcing.mdx +19 -2
- package/docs/how-it-works/framework-integrations.mdx +68 -11
- package/docs/observability/index.mdx +1 -1
- package/docs/testing/index.mdx +1 -1
- package/docs/testing/server-based.mdx +59 -16
- package/package.json +10 -10
|
@@ -139,12 +139,41 @@ On Vercel, workflow runs are pegged to the deployment that started them. This me
|
|
|
139
139
|
|
|
140
140
|
This ensures long-running workflows complete reliably without being affected by subsequent deployments.
|
|
141
141
|
|
|
142
|
+
## Security
|
|
143
|
+
|
|
144
|
+
### Consumer function security
|
|
145
|
+
|
|
146
|
+
Workflow handler functions on Vercel are not accessible through public endpoints. During the build step, the Workflow SDK registers each handler as only reachable by [Vercel Queue](https://vercel.com/docs/queues), by using the `experimentalTriggers` configuration in `.vc-config.json`:
|
|
147
|
+
|
|
148
|
+
```json title=".vc-config.json (step handler)"
|
|
149
|
+
{
|
|
150
|
+
"experimentalTriggers": [
|
|
151
|
+
{
|
|
152
|
+
"type": "queue/v2beta",
|
|
153
|
+
"topic": "__wkf_step_*",
|
|
154
|
+
"consumer": "default",
|
|
155
|
+
}
|
|
156
|
+
]
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Practically, this means:
|
|
161
|
+
|
|
162
|
+
- You don't need to add authentication or authorization logic to workflow handlers
|
|
163
|
+
- Unauthorized requests can never reach the step or workflow functions
|
|
164
|
+
- Only messages delivered through Vercel Queues can trigger execution
|
|
165
|
+
- Handlers receive only a message ID that must be retrieved from Vercel's backend, making it impossible to craft custom payloads
|
|
166
|
+
|
|
167
|
+
<Callout>
|
|
168
|
+
This configuration is managed entirely by the Workflow SDK build step. You should not need to write this yourself. If you are writing a custom integration, see [Framework Integrations — Security](/docs/how-it-works/framework-integrations#security) for more details.
|
|
169
|
+
</Callout>
|
|
170
|
+
|
|
142
171
|
## How It Works
|
|
143
172
|
|
|
144
173
|
The Vercel World uses Vercel's infrastructure for workflow execution:
|
|
145
174
|
|
|
146
175
|
- **Storage** - Workflow data is stored in Vercel's cloud with automatic replication and [end-to-end encryption](/docs/how-it-works/encryption)
|
|
147
|
-
- **Queuing** - Steps are distributed across serverless functions with automatic retries
|
|
176
|
+
- **Queuing** - Steps are distributed across serverless functions via [Vercel Queues](https://vercel.com/docs/queues) with automatic retries and [consumer function security](#consumer-function-security)
|
|
148
177
|
- **Authentication** - OIDC tokens provide secure, automatic authentication
|
|
149
178
|
|
|
150
179
|
For more details, see the [Vercel Workflow documentation](https://vercel.com/docs/workflow).
|
|
@@ -15,7 +15,7 @@ This error occurs when you try to create a hook with a token that is already in
|
|
|
15
15
|
## Error Message
|
|
16
16
|
|
|
17
17
|
```
|
|
18
|
-
Hook token
|
|
18
|
+
Hook token "<token>" is already in use by another workflow
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
## Why This Happens
|
|
@@ -69,7 +69,7 @@ async function read(filePath: string) {
|
|
|
69
69
|
These common Node.js core modules cannot be used in workflow functions:
|
|
70
70
|
|
|
71
71
|
- File system: `fs`, `path`
|
|
72
|
-
- Network: `http`, `https`, `net`, `dns
|
|
72
|
+
- Network: `http`, `https`, `net`, `dns`
|
|
73
73
|
- Process: `child_process`, `cluster`
|
|
74
74
|
- Crypto: `crypto` (use Web Crypto API instead)
|
|
75
75
|
- Operating system: `os`
|
|
@@ -1,107 +1,132 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: start-invalid-workflow-function
|
|
3
|
-
description:
|
|
3
|
+
description: The function passed to start() must be a transformed workflow function.
|
|
4
4
|
type: troubleshooting
|
|
5
|
-
summary:
|
|
5
|
+
summary: Fix invalid workflow function errors by adding "use workflow" and enabling your framework integration.
|
|
6
6
|
prerequisites:
|
|
7
7
|
- /docs/foundations/starting-workflows
|
|
8
8
|
related:
|
|
9
9
|
- /docs/api-reference/workflow-api/start
|
|
10
|
+
- /docs/getting-started/next
|
|
11
|
+
- /docs/api-reference/workflow-next/with-workflow
|
|
10
12
|
---
|
|
11
13
|
|
|
12
|
-
This error occurs when
|
|
14
|
+
This error occurs when `start()` receives a function that does not have Workflow SDK's generated workflow metadata. In practice, that usually means the function is missing `"use workflow"` or the file was never transformed by your framework integration.
|
|
13
15
|
|
|
14
16
|
## Error Message
|
|
15
17
|
|
|
16
18
|
```
|
|
17
|
-
'start' received an invalid workflow function. Ensure the Workflow SDK
|
|
18
|
-
is configured correctly and the function includes a 'use workflow' directive.
|
|
19
|
+
'start' received an invalid workflow function. Ensure the Workflow SDK is configured correctly and the function includes a 'use workflow' directive.
|
|
19
20
|
```
|
|
20
21
|
|
|
21
22
|
## Why This Happens
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
This error typically happens when:
|
|
26
|
-
|
|
27
|
-
* The function is missing the `"use workflow"` directive
|
|
28
|
-
* The workflow isn't being built/transformed correctly
|
|
29
|
-
* The function isn't exported from the workflow file
|
|
30
|
-
* The wrong function is being imported
|
|
24
|
+
`start()` expects an imported workflow function, not just any async function. During compilation, Workflow SDK transforms files that contain `"use workflow"` and attaches generated metadata such as the workflow ID. If that transform never runs, or if you pass a wrapper function instead of the transformed export, `start()` cannot identify what to enqueue and throws this error.
|
|
31
25
|
|
|
32
26
|
## Common Causes
|
|
33
27
|
|
|
34
|
-
### Missing `"use workflow"`
|
|
28
|
+
### Missing `"use workflow"`
|
|
35
29
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// workflow logic
|
|
40
|
-
return { status: "completed" };
|
|
41
|
-
}
|
|
42
|
-
```
|
|
30
|
+
{/* @skip-typecheck: incomplete code sample */}
|
|
31
|
+
```typescript lineNumbers
|
|
32
|
+
import { start } from "workflow/api";
|
|
43
33
|
|
|
44
|
-
|
|
34
|
+
export async function sendReminder(email: string) {
|
|
35
|
+
await sendEmail(email);
|
|
36
|
+
}
|
|
45
37
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
38
|
+
export async function POST() {
|
|
39
|
+
await start(sendReminder, ["hello@example.com"]);
|
|
40
|
+
return new Response("ok");
|
|
41
|
+
}
|
|
50
42
|
|
|
51
|
-
|
|
52
|
-
|
|
43
|
+
async function sendEmail(email: string) {
|
|
44
|
+
"use step";
|
|
45
|
+
console.log(`Sending email to ${email}`);
|
|
53
46
|
}
|
|
54
47
|
```
|
|
55
48
|
|
|
56
|
-
|
|
49
|
+
**Fix:** Add `"use workflow"` to the workflow function.
|
|
57
50
|
|
|
58
|
-
|
|
51
|
+
{/* @skip-typecheck: incomplete code sample */}
|
|
52
|
+
```typescript lineNumbers
|
|
59
53
|
import { start } from "workflow/api";
|
|
60
|
-
// Error - importing step function instead of workflow
|
|
61
|
-
import { processStep } from "@/workflows/order"; // [!code highlight]
|
|
62
54
|
|
|
63
|
-
export async function
|
|
64
|
-
|
|
65
|
-
|
|
55
|
+
export async function sendReminder(email: string) {
|
|
56
|
+
"use workflow"; // [!code highlight]
|
|
57
|
+
await sendEmail(email);
|
|
66
58
|
}
|
|
67
|
-
```
|
|
68
59
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
// Fixed - import workflow function
|
|
74
|
-
import { processOrder } from "@/workflows/order"; // [!code highlight]
|
|
60
|
+
export async function POST() {
|
|
61
|
+
await start(sendReminder, ["hello@example.com"]); // [!code highlight]
|
|
62
|
+
return new Response("ok");
|
|
63
|
+
}
|
|
75
64
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
65
|
+
async function sendEmail(email: string) {
|
|
66
|
+
"use step";
|
|
67
|
+
console.log(`Sending email to ${email}`);
|
|
79
68
|
}
|
|
80
69
|
```
|
|
81
70
|
|
|
82
|
-
###
|
|
71
|
+
### Missing `withWorkflow()` in `next.config.ts`
|
|
83
72
|
|
|
84
|
-
|
|
85
|
-
|
|
73
|
+
{/* @skip-typecheck: incomplete code sample */}
|
|
74
|
+
```typescript title="next.config.ts" lineNumbers
|
|
86
75
|
import type { NextConfig } from "next";
|
|
87
76
|
|
|
88
|
-
const nextConfig: NextConfig = {
|
|
89
|
-
// your config
|
|
90
|
-
};
|
|
77
|
+
const nextConfig: NextConfig = {};
|
|
91
78
|
|
|
92
79
|
export default nextConfig;
|
|
93
80
|
```
|
|
94
81
|
|
|
95
|
-
**
|
|
82
|
+
**Fix:** Wrap the config with `withWorkflow()` so workflow files are transformed.
|
|
96
83
|
|
|
97
|
-
```typescript
|
|
98
|
-
// Fixed - includes withWorkflow
|
|
99
|
-
import { withWorkflow } from "workflow/next"; // [!code highlight}
|
|
84
|
+
```typescript title="next.config.ts" lineNumbers
|
|
100
85
|
import type { NextConfig } from "next";
|
|
86
|
+
import { withWorkflow } from "workflow/next"; // [!code highlight]
|
|
101
87
|
|
|
102
|
-
const nextConfig: NextConfig = {
|
|
103
|
-
// your config
|
|
104
|
-
};
|
|
88
|
+
const nextConfig: NextConfig = {};
|
|
105
89
|
|
|
106
90
|
export default withWorkflow(nextConfig); // [!code highlight]
|
|
107
91
|
```
|
|
92
|
+
|
|
93
|
+
### Passing a wrapper function instead of the imported workflow
|
|
94
|
+
|
|
95
|
+
{/* @skip-typecheck: incomplete code sample */}
|
|
96
|
+
```typescript lineNumbers
|
|
97
|
+
import { start } from "workflow/api";
|
|
98
|
+
import { sendReminder } from "./workflows/send-reminder";
|
|
99
|
+
|
|
100
|
+
export async function POST() {
|
|
101
|
+
// Does NOT work
|
|
102
|
+
await start(async () => sendReminder("hello@example.com"));
|
|
103
|
+
return new Response("ok");
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
**Fix:** Pass the imported workflow function directly and provide arguments in the second parameter.
|
|
108
|
+
|
|
109
|
+
```typescript lineNumbers
|
|
110
|
+
import { start } from "workflow/api";
|
|
111
|
+
import { sendReminder } from "./workflows/send-reminder";
|
|
112
|
+
|
|
113
|
+
export async function POST() {
|
|
114
|
+
await start(sendReminder, ["hello@example.com"]); // [!code highlight]
|
|
115
|
+
return new Response("ok");
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Checklist
|
|
120
|
+
|
|
121
|
+
Before calling `start()`:
|
|
122
|
+
|
|
123
|
+
1. Confirm the function includes `"use workflow"` as its first statement.
|
|
124
|
+
2. Confirm your framework integration is enabled (for Next.js, wrap `next.config.ts` with [`withWorkflow()`](/docs/api-reference/workflow-next/with-workflow)).
|
|
125
|
+
3. Pass the imported workflow function directly to `start()`, not a wrapper callback.
|
|
126
|
+
4. Keep the function in a file that goes through Workflow DevKit's transform step.
|
|
127
|
+
|
|
128
|
+
## Related
|
|
129
|
+
|
|
130
|
+
- [`start()`](/docs/api-reference/workflow-api/start)
|
|
131
|
+
- [`withWorkflow()`](/docs/api-reference/workflow-next/with-workflow)
|
|
132
|
+
- [Next.js Getting Started](/docs/getting-started/next)
|
|
@@ -144,7 +144,7 @@ export async function POST(request: Request) {
|
|
|
144
144
|
}
|
|
145
145
|
```
|
|
146
146
|
|
|
147
|
-
Your workflow can
|
|
147
|
+
Your workflow can obtain a writable stream using [`getWritable()`](/docs/api-reference/workflow/get-writable):
|
|
148
148
|
|
|
149
149
|
```typescript lineNumbers
|
|
150
150
|
import { getWritable } from "workflow";
|
|
@@ -44,7 +44,7 @@ Use the `Run` object's `readable` property to consume the stream from your API r
|
|
|
44
44
|
|
|
45
45
|
```typescript title="app/api/stream/route.ts" lineNumbers
|
|
46
46
|
import { start } from "workflow/api";
|
|
47
|
-
import { simpleStreamingWorkflow } from "./workflows/simple";
|
|
47
|
+
import { simpleStreamingWorkflow } from "./workflows/simple-streaming";
|
|
48
48
|
|
|
49
49
|
export async function POST() {
|
|
50
50
|
const run = await start(simpleStreamingWorkflow);
|
|
@@ -235,6 +235,23 @@ npx astro add vercel
|
|
|
235
235
|
|
|
236
236
|
Additionally, check the [Deploying](/docs/deploying) section to learn how your workflows can be deployed elsewhere.
|
|
237
237
|
|
|
238
|
+
## Troubleshooting
|
|
239
|
+
|
|
240
|
+
### `start()` says it received an invalid workflow function
|
|
241
|
+
|
|
242
|
+
If you see this error:
|
|
243
|
+
|
|
244
|
+
```
|
|
245
|
+
'start' received an invalid workflow function. Ensure the Workflow Development Kit is configured correctly and the function includes a 'use workflow' directive.
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
Check both of these first:
|
|
249
|
+
|
|
250
|
+
1. The workflow function includes `"use workflow"`.
|
|
251
|
+
2. Your `astro.config.mjs` includes the `workflow()` integration.
|
|
252
|
+
|
|
253
|
+
See [start-invalid-workflow-function](/docs/errors/start-invalid-workflow-function) for full examples and fixes.
|
|
254
|
+
|
|
238
255
|
## Next Steps
|
|
239
256
|
|
|
240
257
|
* Learn more about the [Foundations](/docs/foundations).
|
|
@@ -262,6 +262,23 @@ Workflow SDK apps currently work best when deployed to [Vercel](https://vercel.c
|
|
|
262
262
|
|
|
263
263
|
Check the [Deploying](/docs/deploying) section to learn how your workflows can be deployed elsewhere.
|
|
264
264
|
|
|
265
|
+
## Troubleshooting
|
|
266
|
+
|
|
267
|
+
### `start()` says it received an invalid workflow function
|
|
268
|
+
|
|
269
|
+
If you see this error:
|
|
270
|
+
|
|
271
|
+
```
|
|
272
|
+
'start' received an invalid workflow function. Ensure the Workflow Development Kit is configured correctly and the function includes a 'use workflow' directive.
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
Check both of these first:
|
|
276
|
+
|
|
277
|
+
1. The workflow function includes `"use workflow"`.
|
|
278
|
+
2. Your Nitro config includes the `workflow/nitro` module.
|
|
279
|
+
|
|
280
|
+
See [start-invalid-workflow-function](/docs/errors/start-invalid-workflow-function) for full examples and fixes.
|
|
281
|
+
|
|
265
282
|
## Next Steps
|
|
266
283
|
|
|
267
284
|
- Learn more about the [Foundations](/docs/foundations).
|
|
@@ -249,6 +249,23 @@ Workflow SDK apps currently work best when deployed to [Vercel](https://vercel.c
|
|
|
249
249
|
|
|
250
250
|
Check the [Deploying](/docs/deploying) section to learn how your workflows can be deployed elsewhere.
|
|
251
251
|
|
|
252
|
+
## Troubleshooting
|
|
253
|
+
|
|
254
|
+
### `start()` says it received an invalid workflow function
|
|
255
|
+
|
|
256
|
+
If you see this error:
|
|
257
|
+
|
|
258
|
+
```
|
|
259
|
+
'start' received an invalid workflow function. Ensure the Workflow Development Kit is configured correctly and the function includes a 'use workflow' directive.
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
Check both of these first:
|
|
263
|
+
|
|
264
|
+
1. The workflow function includes `"use workflow"`.
|
|
265
|
+
2. Your Nitro config includes the `workflow/nitro` module.
|
|
266
|
+
|
|
267
|
+
See [start-invalid-workflow-function](/docs/errors/start-invalid-workflow-function) for full examples and fixes.
|
|
268
|
+
|
|
252
269
|
## Next Steps
|
|
253
270
|
|
|
254
271
|
- Learn more about the [Foundations](/docs/foundations).
|
|
@@ -244,6 +244,23 @@ Workflow SDK apps currently work best when deployed to [Vercel](https://vercel.c
|
|
|
244
244
|
|
|
245
245
|
Check the [Deploying](/docs/deploying) section to learn how your workflows can be deployed elsewhere.
|
|
246
246
|
|
|
247
|
+
## Troubleshooting
|
|
248
|
+
|
|
249
|
+
### `start()` says it received an invalid workflow function
|
|
250
|
+
|
|
251
|
+
If you see this error:
|
|
252
|
+
|
|
253
|
+
```
|
|
254
|
+
'start' received an invalid workflow function. Ensure the Workflow Development Kit is configured correctly and the function includes a 'use workflow' directive.
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
Check both of these first:
|
|
258
|
+
|
|
259
|
+
1. The workflow function includes `"use workflow"`.
|
|
260
|
+
2. Your Nitro config includes the `workflow/nitro` module.
|
|
261
|
+
|
|
262
|
+
See [start-invalid-workflow-function](/docs/errors/start-invalid-workflow-function) for full examples and fixes.
|
|
263
|
+
|
|
247
264
|
## Next Steps
|
|
248
265
|
|
|
249
266
|
- Learn more about the [Foundations](/docs/foundations).
|
|
@@ -41,15 +41,18 @@ cd my-workflow-app
|
|
|
41
41
|
npm i workflow @workflow/nest
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
###
|
|
44
|
+
### Choose Your Module Format
|
|
45
45
|
|
|
46
|
-
NestJS
|
|
46
|
+
NestJS projects using `@workflow/nest` can compile as either ESM or CommonJS. Choose the setup that matches your SWC output instead of assuming ESM is required.
|
|
47
|
+
|
|
48
|
+
#### ESM (default)
|
|
49
|
+
|
|
50
|
+
Use this when your NestJS project is configured as an ES module app.
|
|
47
51
|
|
|
48
52
|
```json title="package.json" lineNumbers
|
|
49
53
|
{
|
|
50
54
|
"name": "my-workflow-app",
|
|
51
|
-
"type": "module"
|
|
52
|
-
// ... rest of your config
|
|
55
|
+
"type": "module"
|
|
53
56
|
}
|
|
54
57
|
```
|
|
55
58
|
|
|
@@ -57,6 +60,29 @@ NestJS with SWC uses ES modules. Add `"type": "module"` to your `package.json`:
|
|
|
57
60
|
When using ESM with NestJS, local imports must include the `.js` extension (e.g., `import { AppModule } from './app.module.js'`). This applies even though your source files are `.ts`.
|
|
58
61
|
</Callout>
|
|
59
62
|
|
|
63
|
+
#### CommonJS
|
|
64
|
+
|
|
65
|
+
Use this when your NestJS project compiles CommonJS via SWC.
|
|
66
|
+
|
|
67
|
+
```typescript title="src/app.module.ts" lineNumbers
|
|
68
|
+
import { Module } from '@nestjs/common';
|
|
69
|
+
import { WorkflowModule } from '@workflow/nest';
|
|
70
|
+
|
|
71
|
+
@Module({
|
|
72
|
+
imports: [
|
|
73
|
+
WorkflowModule.forRoot({
|
|
74
|
+
moduleType: 'commonjs',
|
|
75
|
+
distDir: 'dist',
|
|
76
|
+
}),
|
|
77
|
+
],
|
|
78
|
+
})
|
|
79
|
+
export class AppModule {}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
<Callout type="info">
|
|
83
|
+
`distDir` should match the directory where NestJS writes compiled `.js` files. In the default SWC setup, that is `dist`.
|
|
84
|
+
</Callout>
|
|
85
|
+
|
|
60
86
|
### Configure NestJS to use SWC
|
|
61
87
|
|
|
62
88
|
NestJS supports SWC as an alternative compiler for faster builds. The Workflow SDK uses an SWC plugin to transform workflow files.
|
|
@@ -141,7 +167,7 @@ To enable helpful hints in your IDE, setup the workflow plugin in `tsconfig.json
|
|
|
141
167
|
|
|
142
168
|
## Import the WorkflowModule
|
|
143
169
|
|
|
144
|
-
In your `app.module.ts`, import the `WorkflowModule
|
|
170
|
+
In your `app.module.ts`, import the `WorkflowModule` and keep the module format you chose above.
|
|
145
171
|
|
|
146
172
|
```typescript title="src/app.module.ts" lineNumbers
|
|
147
173
|
import { Module } from '@nestjs/common';
|
|
@@ -157,6 +183,20 @@ import { AppService } from './app.service.js';
|
|
|
157
183
|
export class AppModule {}
|
|
158
184
|
```
|
|
159
185
|
|
|
186
|
+
<Callout type="info">
|
|
187
|
+
If you chose CommonJS above, keep the CommonJS options here as well:
|
|
188
|
+
|
|
189
|
+
{/* @skip-typecheck - config snippet, full import shown above */}
|
|
190
|
+
```typescript
|
|
191
|
+
WorkflowModule.forRoot({
|
|
192
|
+
moduleType: 'commonjs',
|
|
193
|
+
distDir: 'dist',
|
|
194
|
+
})
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
The `.js` local import specifiers in this example are the ESM form.
|
|
198
|
+
</Callout>
|
|
199
|
+
|
|
160
200
|
The `WorkflowModule` handles workflow bundle building and provides HTTP routing for workflow execution at `.well-known/workflow/v1/`.
|
|
161
201
|
|
|
162
202
|
</Step>
|
|
@@ -171,6 +211,15 @@ Create a new file for our first workflow in the `src/workflows` directory:
|
|
|
171
211
|
Workflow files must be inside the `src/` directory so they get compiled with the SWC plugin that enables the `start()` function to work correctly.
|
|
172
212
|
</Callout>
|
|
173
213
|
|
|
214
|
+
<Callout type="info">
|
|
215
|
+
If `start()` says it received an invalid workflow function, check both of these first:
|
|
216
|
+
|
|
217
|
+
1. The workflow function includes `"use workflow"`.
|
|
218
|
+
2. The workflow file lives inside `src/` so NestJS compiles it with the SWC plugin.
|
|
219
|
+
|
|
220
|
+
See [start-invalid-workflow-function](/docs/errors/start-invalid-workflow-function) for full examples and fixes.
|
|
221
|
+
</Callout>
|
|
222
|
+
|
|
174
223
|
```typescript title="src/workflows/user-signup.ts" lineNumbers
|
|
175
224
|
import { sleep } from "workflow";
|
|
176
225
|
|
|
@@ -269,6 +318,10 @@ export class AppController {
|
|
|
269
318
|
}
|
|
270
319
|
```
|
|
271
320
|
|
|
321
|
+
<Callout type="info">
|
|
322
|
+
If you chose CommonJS above, use the same local import style as the rest of your NestJS app here too. The `.js` extension shown in this example is the ESM form.
|
|
323
|
+
</Callout>
|
|
324
|
+
|
|
272
325
|
This creates a `POST` endpoint at `/signup` that will trigger your workflow.
|
|
273
326
|
|
|
274
327
|
</Step>
|
|
@@ -324,9 +377,34 @@ WorkflowModule.forRoot({
|
|
|
324
377
|
|
|
325
378
|
// Skip building in production when bundles are pre-built
|
|
326
379
|
skipBuild: false,
|
|
380
|
+
|
|
381
|
+
// SWC module type: 'es6' (default) or 'commonjs'
|
|
382
|
+
// Set to 'commonjs' if your NestJS project compiles to CJS via SWC
|
|
383
|
+
moduleType: 'es6',
|
|
384
|
+
|
|
385
|
+
// Directory where NestJS compiles .ts to .js (default: 'dist')
|
|
386
|
+
// Only used when moduleType is 'commonjs'
|
|
387
|
+
// Should match the outDir in your tsconfig.json
|
|
388
|
+
distDir: 'dist',
|
|
327
389
|
});
|
|
328
390
|
```
|
|
329
391
|
|
|
392
|
+
## Troubleshooting
|
|
393
|
+
|
|
394
|
+
### `start()` says it received an invalid workflow function
|
|
395
|
+
|
|
396
|
+
If you see this error:
|
|
397
|
+
|
|
398
|
+
```
|
|
399
|
+
'start' received an invalid workflow function. Ensure the Workflow Development Kit is configured correctly and the function includes a 'use workflow' directive.
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
Check both of these first:
|
|
403
|
+
|
|
404
|
+
1. The workflow function includes `"use workflow"`.
|
|
405
|
+
2. Your NestJS app imports and registers the `WorkflowModule`.
|
|
406
|
+
|
|
407
|
+
See [start-invalid-workflow-function](/docs/errors/start-invalid-workflow-function) for full examples and fixes.
|
|
330
408
|
## Next Steps
|
|
331
409
|
|
|
332
410
|
- Learn more about the [Foundations](/docs/foundations).
|
|
@@ -275,12 +275,27 @@ Build error occurred
|
|
|
275
275
|
Error: Cannot find module 'next/dist/lib/server-external-packages.json'
|
|
276
276
|
```
|
|
277
277
|
|
|
278
|
-
Upgrade to `workflow@4.0
|
|
278
|
+
Upgrade to `workflow@4.2.0` or later:
|
|
279
279
|
|
|
280
280
|
```package-install
|
|
281
281
|
workflow@latest
|
|
282
282
|
```
|
|
283
283
|
|
|
284
|
+
### `start()` says it received an invalid workflow function
|
|
285
|
+
|
|
286
|
+
If you see this error:
|
|
287
|
+
|
|
288
|
+
```
|
|
289
|
+
'start' received an invalid workflow function. Ensure the Workflow Development Kit is configured correctly and the function includes a 'use workflow' directive.
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
Check both of these first:
|
|
293
|
+
|
|
294
|
+
1. The workflow function includes `"use workflow"`.
|
|
295
|
+
2. Your `next.config.ts` is wrapped with [`withWorkflow()`](/docs/api-reference/workflow-next/with-workflow).
|
|
296
|
+
|
|
297
|
+
See [start-invalid-workflow-function](/docs/errors/start-invalid-workflow-function) for full examples and fixes.
|
|
298
|
+
|
|
284
299
|
## Next Steps
|
|
285
300
|
|
|
286
301
|
* Learn more about the [Foundations](/docs/foundations).
|
|
@@ -228,6 +228,23 @@ Workflow SDK apps currently work best when deployed to [Vercel](https://vercel.c
|
|
|
228
228
|
|
|
229
229
|
Check the [Deploying](/docs/deploying) section to learn how your workflows can be deployed elsewhere.
|
|
230
230
|
|
|
231
|
+
## Troubleshooting
|
|
232
|
+
|
|
233
|
+
### `start()` says it received an invalid workflow function
|
|
234
|
+
|
|
235
|
+
If you see this error:
|
|
236
|
+
|
|
237
|
+
```
|
|
238
|
+
'start' received an invalid workflow function. Ensure the Workflow Development Kit is configured correctly and the function includes a 'use workflow' directive.
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
Check both of these first:
|
|
242
|
+
|
|
243
|
+
1. The workflow function includes `"use workflow"`.
|
|
244
|
+
2. Your Nitro config includes the `workflow/nitro` module.
|
|
245
|
+
|
|
246
|
+
See [start-invalid-workflow-function](/docs/errors/start-invalid-workflow-function) for full examples and fixes.
|
|
247
|
+
|
|
231
248
|
## Next Steps
|
|
232
249
|
|
|
233
250
|
- Learn more about the [Foundations](/docs/foundations).
|
|
@@ -229,6 +229,23 @@ Workflow SDK apps currently work best when deployed to [Vercel](https://vercel.c
|
|
|
229
229
|
|
|
230
230
|
Check the [Deploying](/docs/deploying) section to learn how your workflows can be deployed elsewhere.
|
|
231
231
|
|
|
232
|
+
## Troubleshooting
|
|
233
|
+
|
|
234
|
+
### `start()` says it received an invalid workflow function
|
|
235
|
+
|
|
236
|
+
If you see this error:
|
|
237
|
+
|
|
238
|
+
```
|
|
239
|
+
'start' received an invalid workflow function. Ensure the Workflow Development Kit is configured correctly and the function includes a 'use workflow' directive.
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
Check both of these first:
|
|
243
|
+
|
|
244
|
+
1. The workflow function includes `"use workflow"`.
|
|
245
|
+
2. Your `nuxt.config.ts` includes the `workflow/nuxt` module.
|
|
246
|
+
|
|
247
|
+
See [start-invalid-workflow-function](/docs/errors/start-invalid-workflow-function) for full examples and fixes.
|
|
248
|
+
|
|
232
249
|
## Next Steps
|
|
233
250
|
|
|
234
251
|
- Learn more about the [Foundations](/docs/foundations).
|
|
@@ -228,6 +228,23 @@ Workflow SDK apps currently work best when deployed to [Vercel](https://vercel.c
|
|
|
228
228
|
|
|
229
229
|
Check the [Deploying](/docs/deploying) section to learn how your workflows can be deployed elsewhere.
|
|
230
230
|
|
|
231
|
+
## Troubleshooting
|
|
232
|
+
|
|
233
|
+
### `start()` says it received an invalid workflow function
|
|
234
|
+
|
|
235
|
+
If you see this error:
|
|
236
|
+
|
|
237
|
+
```
|
|
238
|
+
'start' received an invalid workflow function. Ensure the Workflow Development Kit is configured correctly and the function includes a 'use workflow' directive.
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
Check both of these first:
|
|
242
|
+
|
|
243
|
+
1. The workflow function includes `"use workflow"`.
|
|
244
|
+
2. Your `vite.config.ts` includes the `workflow/sveltekit` plugin.
|
|
245
|
+
|
|
246
|
+
See [start-invalid-workflow-function](/docs/errors/start-invalid-workflow-function) for full examples and fixes.
|
|
247
|
+
|
|
231
248
|
## Next Steps
|
|
232
249
|
|
|
233
250
|
* Learn more about the [Foundations](/docs/foundations).
|
|
@@ -234,6 +234,23 @@ Workflow SDK apps currently work best when deployed to [Vercel](https://vercel.c
|
|
|
234
234
|
|
|
235
235
|
Check the [Deploying](/docs/deploying) section to learn how your workflows can be deployed elsewhere.
|
|
236
236
|
|
|
237
|
+
## Troubleshooting
|
|
238
|
+
|
|
239
|
+
### `start()` says it received an invalid workflow function
|
|
240
|
+
|
|
241
|
+
If you see this error:
|
|
242
|
+
|
|
243
|
+
```
|
|
244
|
+
'start' received an invalid workflow function. Ensure the Workflow Development Kit is configured correctly and the function includes a 'use workflow' directive.
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
Check both of these first:
|
|
248
|
+
|
|
249
|
+
1. The workflow function includes `"use workflow"`.
|
|
250
|
+
2. Your `vite.config.ts` includes the `workflow/vite` plugin.
|
|
251
|
+
|
|
252
|
+
See [start-invalid-workflow-function](/docs/errors/start-invalid-workflow-function) for full examples and fixes.
|
|
253
|
+
|
|
237
254
|
## Next Steps
|
|
238
255
|
|
|
239
256
|
* Learn more about the [Foundations](/docs/foundations).
|