|
1 | 1 | --- |
2 | 2 | pcx_content_type: concept |
3 | 3 | title: Known issues |
4 | | - |
5 | 4 | --- |
6 | 5 |
|
7 | | -import { GlossaryTooltip } from "~/components"; |
| 6 | +import { |
| 7 | + GlossaryTooltip, |
| 8 | + Steps, |
| 9 | + WranglerConfig, |
| 10 | + PackageManagers, |
| 11 | +} from "~/components"; |
8 | 12 |
|
9 | 13 | Durable Objects is generally available. However, there are some known issues. |
10 | 14 |
|
@@ -36,4 +40,75 @@ The Workers editor in the [Cloudflare dashboard](https://dash.cloudflare.com/) a |
36 | 40 |
|
37 | 41 | Currently, when developing locally (using `npx wrangler dev`), Durable Object [alarm methods](/durable-objects/api/alarms) may fail after a hot reload (if you edit the code while the code is running locally). |
38 | 42 |
|
39 | | -To avoid this issue, when using Durable Object alarms, close and restart your `wrangler dev` command after editing your code. |
| 43 | +To avoid this issue, when using Durable Object alarms, close and restart your `wrangler dev` command after editing your code. |
| 44 | + |
| 45 | +## Local development with web frameworks |
| 46 | + |
| 47 | +When developing a Pages or Workers Assets application, you may have to define your Durable Object in a separate Worker in order to develop locally. |
| 48 | +This only applies to frameworks that use a development server that runs in Node.js. We are working to improve this experience - for example, frameworks that use the Cloudflare Vite plugin do not have this issue. |
| 49 | + |
| 50 | +For now, you can set up your project like this to enable local development. |
| 51 | + |
| 52 | +<Steps> |
| 53 | +1. Create a new Worker with your Durable Object code. |
| 54 | + |
| 55 | + ```ts title="src/index.ts" |
| 56 | + export class MyDurableObject extends DurableObject { |
| 57 | + // Your DO code goes here |
| 58 | + } |
| 59 | + |
| 60 | + export default { |
| 61 | + fetch() { |
| 62 | + // Doesn't have to do anything, but a DO cannot be the default export |
| 63 | + return new Response("Hello, world!"); |
| 64 | + }, |
| 65 | + }; |
| 66 | + ``` |
| 67 | + |
| 68 | +2. Create a new Wrangler config file for this Worker. |
| 69 | + |
| 70 | + <WranglerConfig> |
| 71 | + ```json |
| 72 | + { |
| 73 | + "name": "external-do-worker", |
| 74 | + "main": "src/index.ts", |
| 75 | + "compatibility_date": "XXXX-XX-XX" |
| 76 | + } |
| 77 | + ``` |
| 78 | + </WranglerConfig> |
| 79 | + |
| 80 | +3. Update your **original** Durable Object bindings in your pre-existing Wrangler config file to include the `script_name` field. This should be the same as the `name` field in the new Worker's config. |
| 81 | + |
| 82 | + <WranglerConfig> |
| 83 | + |
| 84 | + ```json |
| 85 | + { |
| 86 | + ... |
| 87 | + "durable_objects": { |
| 88 | + "bindings": [ |
| 89 | + { |
| 90 | + "name": "BINDING", |
| 91 | + "class_name": "MyDurableObject", |
| 92 | + "script_name": "external-do-worker", |
| 93 | + }, |
| 94 | + ], |
| 95 | + }, |
| 96 | + ... |
| 97 | + }, |
| 98 | + ``` |
| 99 | + |
| 100 | + </WranglerConfig> |
| 101 | + |
| 102 | +4. Develop locally |
| 103 | + |
| 104 | + If you are not using RPC with your Durable Object, you can run a separate Wrangler dev session alongside your framework development server. |
| 105 | + |
| 106 | + Otherwise, you can build your application and run both Workers in the same Wrangler dev session. |
| 107 | + |
| 108 | + If you are using Pages: |
| 109 | + <PackageManagers type="exec" pkg="wrangler" args="pages dev -c path/to/pages/wrangler.json -c path/to/external-do-worker/wrangler.json" /> |
| 110 | + |
| 111 | + If you are using Workers with Assets: |
| 112 | + <PackageManagers type="exec" pkg="wrangler" args="dev -c path/to/workers-assets/wrangler.json -c path/to/external-do-worker/wrangler.json" /> |
| 113 | + |
| 114 | +</Steps> |
0 commit comments