diff --git a/.changeset/hot-poems-march.md b/.changeset/hot-poems-march.md new file mode 100644 index 000000000000..e5133c58b7ff --- /dev/null +++ b/.changeset/hot-poems-march.md @@ -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. diff --git a/packages/wrangler/src/__tests__/dev.test.tsx b/packages/wrangler/src/__tests__/dev.test.tsx index 88c4c8eec29b..d34e053b0bc7 100644 --- a/packages/wrangler/src/__tests__/dev.test.tsx +++ b/packages/wrangler/src/__tests__/dev.test.tsx @@ -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: @@ -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" }, }); @@ -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( @@ -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( @@ -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( @@ -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( @@ -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( @@ -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( @@ -1646,7 +1646,7 @@ describe("wrangler dev", () => { writeWranglerToml({ tail_consumers: [{ service: "" }], }); - fs.openSync("public", "w"); + fs.mkdirSync("public"); await expect( runWrangler("dev --experimental-assets public") ).rejects.toThrowErrorMatchingInlineSnapshot( @@ -1659,13 +1659,34 @@ describe("wrangler dev", () => { experimental_assets: { directory: "./public" }, tail_consumers: [{ service: "" }], }); - 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", () => { diff --git a/packages/wrangler/src/dev.tsx b/packages/wrangler/src/dev.tsx index 9e971c5f54ce..36cc20e0ac65 100644 --- a/packages/wrangler/src/dev.tsx +++ b/packages/wrangler/src/dev.tsx @@ -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);