diff --git a/.changeset/eleven-cobras-repeat.md b/.changeset/eleven-cobras-repeat.md new file mode 100644 index 000000000000..3c52d76c40ed --- /dev/null +++ b/.changeset/eleven-cobras-repeat.md @@ -0,0 +1,5 @@ +--- +"wrangler": patch +--- + +fix: throw a better error if there is an "ASSETS" user binding in a Pages projects diff --git a/packages/wrangler/src/__tests__/configuration.pages.test.ts b/packages/wrangler/src/__tests__/configuration.pages.test.ts index 3106c2122f56..9b7ae8155208 100644 --- a/packages/wrangler/src/__tests__/configuration.pages.test.ts +++ b/packages/wrangler/src/__tests__/configuration.pages.test.ts @@ -767,5 +767,47 @@ describe("normalizeAndValidateConfig()", () => { ); }); }); + + it("should error if there is a user binding named ASSETS at the top-level", () => { + const { diagnostics } = normalizeAndValidateConfig( + { + ...pagesRawConfig, + kv_namespaces: [ + { + binding: "ASSETS", + id: "1234", + }, + ], + }, + undefined, + { env: undefined } + ); + + expect(diagnostics.errors).toEqual([ + "The name 'ASSETS' is reserved in Pages projects. Please use a different name for your KV Namespaces binding.", + ]); + }); + + it("should error if there is a user binding named ASSETS in a named environment", () => { + const { diagnostics } = normalizeAndValidateConfig( + { + ...pagesRawConfig, + env: { + preview: { + ...pagesRawConfig.env?.preview, + vars: { ASSETS: "test_value" }, + }, + }, + }, + undefined, + { + env: "preview", + } + ); + + expect(diagnostics.errors).toEqual([ + "The name 'ASSETS' is reserved in Pages projects. Please use a different name for your Vars binding.", + ]); + }); }); }); diff --git a/packages/wrangler/src/config/validation.ts b/packages/wrangler/src/config/validation.ts index 497dc31eaf2a..ebd47750cbce 100644 --- a/packages/wrangler/src/config/validation.ts +++ b/packages/wrangler/src/config/validation.ts @@ -2773,6 +2773,12 @@ const validateBindingsHaveUniqueNames = ( bindingsGroupedByName[bindingName] = []; } + if (bindingName === "ASSETS" && isPagesConfig(config)) { + diagnostics.errors.push( + `The name 'ASSETS' is reserved in Pages projects. Please use a different name for your ${bindingType} binding.` + ); + } + bindingsGroupedByName[bindingName].push(bindingType); } }