Skip to content

Commit 74d95fd

Browse files
committed
elaborate on error message
1 parent 700ef92 commit 74d95fd

File tree

2 files changed

+68
-9
lines changed

2 files changed

+68
-9
lines changed

fixtures/get-platform-proxy/tests/get-platform-proxy.env.test.ts

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,41 @@ describe("getPlatformProxy - env", () => {
227227
- {"class_name":"MyDurableObject","name":"MY_DURABLE_OBJECT"}
228228
These will not work in local development, but they should work in production.
229229
230-
If you want to develop these locally, you can define your DO "externally" in another worker.
231-
To do this, create another Worker and Wrangler config file. Export your DO from there.
232-
Then, set the \`script_name\` field in your original DO binding to equal the \`name\` field from your new external DO config.
230+
If you want to develop these locally, you can define your DO "externally" in another Worker.
231+
To do this, create another Worker, e.g.
232+
233+
export class MyDurableObject extends DurableObject {
234+
// DO code goes here
235+
}
236+
export default {
237+
fetch() {
238+
// doesn't have to do anything, but DO cannot be the default export
239+
}
240+
}
241+
242+
Also create a new Wrangler config file for this Worker, e.g.
243+
244+
{
245+
"name": "external-do-worker",
246+
"main": "src/index.ts",
247+
"compatibility_date": "XXXX-XX-XX"
248+
}
249+
250+
Then, update your original DO bindings to include the script_name field, e.g.
251+
{
252+
"durable_objects": {
253+
"bindings": [
254+
{
255+
"name": "BINDING",
256+
"class_name": "MyDurableObject",
257+
"script_name": "external-do-worker"
258+
}
259+
]
260+
}
261+
}
233262
234263
You will be able to develop this locally by running:
235-
npx wrangler dev -c path/to/original/wrangler.json -c path/to/external-do/wrangler.json
264+
npx wrangler dev -c path/to/original/wrangler.jsonc -c path/to/external-do/wrangler.jsonc
236265
237266
",
238267
],

packages/wrangler/src/api/integrations/platform/index.ts

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { kCurrentWorker, Miniflare } from "miniflare";
22
import { getAssetsOptions } from "../../../assets";
3-
import { readConfig } from "../../../config";
3+
import { formatConfigSnippet, readConfig } from "../../../config";
44
import { partitionDurableObjectBindings } from "../../../deployment-bundle/entry";
55
import { DEFAULT_MODULE_RULES } from "../../../deployment-bundle/rules";
66
import { getBindings } from "../../../dev";
@@ -109,7 +109,8 @@ export async function getPlatformProxy<
109109
MULTIWORKER: false,
110110
RESOURCES_PROVISION: false,
111111
},
112-
() => getMiniflareOptionsFromConfig(rawConfig, env, options)
112+
() =>
113+
getMiniflareOptionsFromConfig(rawConfig, env, options, options.configPath)
113114
);
114115

115116
const mf = new Miniflare({
@@ -136,7 +137,8 @@ export async function getPlatformProxy<
136137
async function getMiniflareOptionsFromConfig(
137138
rawConfig: Config,
138139
env: string | undefined,
139-
options: GetPlatformProxyOptions
140+
options: GetPlatformProxyOptions,
141+
configPath: string | undefined
140142
): Promise<Partial<MiniflareOptions>> {
141143
const bindings = getBindings(rawConfig, env, true, {});
142144

@@ -149,8 +151,36 @@ async function getMiniflareOptionsFromConfig(
149151
These will not work in local development, but they should work in production.
150152
151153
If you want to develop these locally, you can define your DO "externally" in another Worker.
152-
To do this, create another Worker and Wrangler config file. Export your DO from there.
153-
Then, set the \`script_name\` field in your original DO binding to equal the \`name\` field from your new external DO config.
154+
To do this, create another Worker, e.g.
155+
156+
export class MyDurableObject extends DurableObject {
157+
// DO code goes here
158+
}
159+
export default {
160+
fetch() {
161+
// doesn't have to do anything, but DO cannot be the default export
162+
}
163+
}
164+
165+
Also create a new Wrangler config file for this Worker, e.g.
166+
167+
${formatConfigSnippet({ name: "external-do-worker", main: "src/index.ts", compatibility_date: "XXXX-XX-XX" }, configPath)}
168+
169+
Then, update your original DO bindings to include the script_name field, e.g.
170+
${formatConfigSnippet(
171+
{
172+
durable_objects: {
173+
bindings: [
174+
{
175+
name: "BINDING",
176+
class_name: "MyDurableObject",
177+
script_name: "external-do-worker",
178+
},
179+
],
180+
},
181+
},
182+
configPath
183+
)}
154184
155185
You will be able to develop this locally by running:
156186
npx wrangler dev -c path/to/original/wrangler.jsonc -c path/to/external-do/wrangler.jsonc

0 commit comments

Comments
 (0)