Skip to content

Commit

Permalink
Add Warning about browser rendering when running locally (#7533)
Browse files Browse the repository at this point in the history
* Warn about browser rendering when running locally

* fix warning check

* update snapshot

---------

Co-authored-by: emily-shen <69125074+emily-shen@users.noreply.github.com>
  • Loading branch information
danielgek and emily-shen authored Jan 3, 2025
1 parent b4e0af1 commit 755a27c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/moody-suns-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Add warning about the browser rendering not available on local
17 changes: 17 additions & 0 deletions packages/wrangler/src/__tests__/dev.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1879,6 +1879,23 @@ describe.sequential("wrangler dev", () => {
});
});

describe("`browser rendering binding", () => {
it("should show error when running locally", async () => {
writeWranglerConfig({
browser: {
binding: "MYBROWSER",
},
});
fs.writeFileSync("index.js", `export default {};`);

await expect(
runWrangler("dev index.js")
).rejects.toThrowErrorMatchingInlineSnapshot(
"[Error: Browser Rendering is not supported locally. Please use `wrangler dev --remote` instead.]"
);
});
});

it("should error helpfully if pages_build_output_dir is set", async () => {
writeWranglerConfig({ pages_build_output_dir: "dist", name: "test" });
await expect(runWrangler("dev")).rejects.toThrowErrorMatchingInlineSnapshot(
Expand Down
15 changes: 15 additions & 0 deletions packages/wrangler/src/api/startDevWorker/ConfigController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,21 @@ async function resolveConfig(
);
}

if (resolved.assets && resolved.dev.remote) {
throw new UserError(
"Cannot use assets in remote mode. Workers with assets are only supported in local mode. Please use `wrangler dev`."
);
}

if (
extractBindingsOfType("browser", resolved.bindings).length &&
!resolved.dev.remote
) {
throw new UserError(
"Browser Rendering is not supported locally. Please use `wrangler dev --remote` instead."
);
}

validateAssetsArgsAndConfig(resolved);

const services = extractBindingsOfType("service", resolved.bindings);
Expand Down

0 comments on commit 755a27c

Please sign in to comment.