Skip to content

Commit

Permalink
fix(wrangler): Error if Workers + Assets are run in remote mode (#6778)
Browse files Browse the repository at this point in the history
Workers + Assets are currently supported only in local mode.
We should throw an error if users attempt to use Workers
with assets in remote mode.
  • Loading branch information
CarmenPopoviciu authored Sep 20, 2024
1 parent 2840b9f commit 61dd93a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
7 changes: 7 additions & 0 deletions .changeset/hot-poems-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"wrangler": patch
---

fix: Error if Workers + Assets are run in remote mode

Workers + Assets are currently supported only in local mode. We should throw an error if users attempt to use Workers with assets in remote mode.
41 changes: 31 additions & 10 deletions packages/wrangler/src/__tests__/dev.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ describe("wrangler dev", () => {
directory: "assets",
},
});
fs.openSync("assets", "w");
fs.mkdirSync("assets");
await expect(runWrangler(`dev`)).rejects
.toThrowErrorMatchingInlineSnapshot(`
[Error: Invalid Routes:
Expand Down Expand Up @@ -1505,7 +1505,7 @@ describe("wrangler dev", () => {

describe("--experimental-assets", () => {
it("should not require entry point if using --experimental-assets", async () => {
fs.openSync("assets", "w");
fs.mkdirSync("assets");
writeWranglerToml({
experimental_assets: { directory: "assets" },
});
Expand All @@ -1522,7 +1522,7 @@ describe("wrangler dev", () => {
},
});
fs.writeFileSync("index.js", `export default {};`);
fs.openSync("assets", "w");
fs.mkdirSync("assets");
await expect(
runWrangler("dev")
).rejects.toThrowErrorMatchingInlineSnapshot(
Expand All @@ -1538,7 +1538,7 @@ describe("wrangler dev", () => {
},
});
fs.writeFileSync("index.js", `export default {};`);
fs.openSync("assets", "w");
fs.mkdirSync("assets");
await expect(
runWrangler("dev --experimental-assets assets")
).rejects.toThrowErrorMatchingInlineSnapshot(
Expand All @@ -1559,7 +1559,7 @@ describe("wrangler dev", () => {
},
});
fs.writeFileSync("index.js", `export default {};`);
fs.openSync("assets", "w");
fs.mkdirSync("assets");
await expect(
runWrangler("dev")
).rejects.toThrowErrorMatchingInlineSnapshot(
Expand All @@ -1569,7 +1569,7 @@ describe("wrangler dev", () => {

it("should error if --experimental-assets and --legacy-assets are used together", async () => {
fs.writeFileSync("index.js", `export default {};`);
fs.openSync("assets", "w");
fs.mkdirSync("assets");
await expect(
runWrangler("dev --experimental-assets assets --legacy-assets assets")
).rejects.toThrowErrorMatchingInlineSnapshot(
Expand All @@ -1589,7 +1589,7 @@ describe("wrangler dev", () => {
},
});
fs.writeFileSync("index.js", `export default {};`);
fs.openSync("assets", "w");
fs.mkdirSync("assets");
await expect(
runWrangler("dev --experimental-assets assets")
).rejects.toThrowErrorMatchingInlineSnapshot(
Expand All @@ -1605,7 +1605,7 @@ describe("wrangler dev", () => {
},
});
fs.writeFileSync("index.js", `export default {};`);
fs.openSync("xyz", "w");
fs.mkdirSync("xyz");
await expect(
runWrangler("dev --legacy-assets xyz")
).rejects.toThrowErrorMatchingInlineSnapshot(
Expand Down Expand Up @@ -1646,7 +1646,7 @@ describe("wrangler dev", () => {
writeWranglerToml({
tail_consumers: [{ service: "<TAIL_WORKER_NAME>" }],
});
fs.openSync("public", "w");
fs.mkdirSync("public");
await expect(
runWrangler("dev --experimental-assets public")
).rejects.toThrowErrorMatchingInlineSnapshot(
Expand All @@ -1659,13 +1659,34 @@ describe("wrangler dev", () => {
experimental_assets: { directory: "./public" },
tail_consumers: [{ service: "<TAIL_WORKER_NAME>" }],
});
fs.openSync("public", "w");
fs.mkdirSync("public");
await expect(
runWrangler("dev")
).rejects.toThrowErrorMatchingInlineSnapshot(
`[Error: Cannot use Experimental Assets and tail consumers in the same Worker. Tail Workers are not yet supported for Workers with assets.]`
);
});

it("should error if --experimental-assets and --remote are used together", async () => {
fs.mkdirSync("public");
await expect(
runWrangler("dev --experimental-assets public --remote")
).rejects.toThrowErrorMatchingInlineSnapshot(
`[Error: Cannot use Experimental Assets in remote mode. Workers with assets are only supported in local mode. Please use \`wrangler dev\`.]`
);
});

it("should error if config.experimental_assets and --remote are used together", async () => {
writeWranglerToml({
experimental_assets: { directory: "./public" },
});
fs.mkdirSync("public");
await expect(
runWrangler("dev --remote")
).rejects.toThrowErrorMatchingInlineSnapshot(
`[Error: Cannot use Experimental Assets in remote mode. Workers with assets are only supported in local mode. Please use \`wrangler dev\`.]`
);
});
});

describe("--inspect", () => {
Expand Down
9 changes: 9 additions & 0 deletions packages/wrangler/src/dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,15 @@ export async function startDev(args: StartDevOptions) {
);
}

if (
(args.experimentalAssets || config.experimental_assets) &&
args.remote
) {
throw new UserError(
"Cannot use Experimental Assets in remote mode. Workers with assets are only supported in local mode. Please use `wrangler dev`."
);
}

verifyMutuallyExclusiveAssetsArgsOrConfig(args, config);

let experimentalAssetsOptions = processExperimentalAssetsArg(args, config);
Expand Down

0 comments on commit 61dd93a

Please sign in to comment.