diff --git a/.changeset/config-conflict-error-guidance.md b/.changeset/config-conflict-error-guidance.md new file mode 100644 index 00000000000..6fea3792f1e --- /dev/null +++ b/.changeset/config-conflict-error-guidance.md @@ -0,0 +1,10 @@ +--- +"@cloudflare/workers-utils": patch +"wrangler": patch +--- + +Explain how to resolve a user/deploy configuration conflict + +When a user configuration file and a `.wrangler/deploy/config.json` were found under different base paths, the error stated the conflict but gave no way out of it, leaving the reader to guess whether to move a file, delete one, or run the command somewhere else. + +The message now names the path the deploy configuration would have to sit at to apply, suggests deleting it when it is left over from a previous build or running the command from the directory that owns the intended configuration, and links to the Generated Wrangler configuration documentation. diff --git a/packages/workers-utils/src/config/config-helpers.ts b/packages/workers-utils/src/config/config-helpers.ts index e93f34f43f9..d3d8109ceea 100644 --- a/packages/workers-utils/src/config/config-helpers.ts +++ b/packages/workers-utils/src/config/config-helpers.ts @@ -143,15 +143,23 @@ function findRedirectedWranglerConfig( ); } if (userConfigPath) { - if ( - path.join(path.dirname(userConfigPath), PATH_TO_DEPLOY_CONFIG) !== - deployConfigPath - ) { + const expectedDeployConfigPath = path.join( + path.dirname(userConfigPath), + PATH_TO_DEPLOY_CONFIG + ); + if (expectedDeployConfigPath !== deployConfigPath) { throw new UserError( dedent` Found both a user configuration file at "${path.relative(".", userConfigPath)}" and a deploy configuration file at "${path.relative(".", deployConfigPath)}". But these do not share the same base path so it is not clear which should be used. + + A deploy configuration file is generated by a build tool to redirect Wrangler to the configuration it generated. + It is only applied when it sits alongside the user configuration file, which here would be "${path.relative(".", expectedDeployConfigPath)}". + + Please either delete "${path.relative(".", deployConfigPath)}" if it is left over from a previous build, + or run this command from the directory containing the configuration you want to use. + See https://developers.cloudflare.com/workers/wrangler/configuration/#generated-wrangler-configuration `, { telemetryMessage: false } ); diff --git a/packages/workers-utils/tests/config/findWranglerConfig.test.ts b/packages/workers-utils/tests/config/findWranglerConfig.test.ts index 3a9b75fd5c6..e424a4d35de 100644 --- a/packages/workers-utils/tests/config/findWranglerConfig.test.ts +++ b/packages/workers-utils/tests/config/findWranglerConfig.test.ts @@ -239,7 +239,14 @@ describe("config findWranglerConfig()", () => { expect(normalizeString(`${error}`)).toMatchInlineSnapshot(` "Error: Found both a user configuration file at "foo/wrangler.toml" and a deploy configuration file at "foo/bar/.wrangler/deploy/config.json". - But these do not share the same base path so it is not clear which should be used." + But these do not share the same base path so it is not clear which should be used. + + A deploy configuration file is generated by a build tool to redirect Wrangler to the configuration it generated. + It is only applied when it sits alongside the user configuration file, which here would be "foo/.wrangler/deploy/config.json". + + Please either delete "foo/bar/.wrangler/deploy/config.json" if it is left over from a previous build, + or run this command from the directory containing the configuration you want to use. + See https://developers.cloudflare.com/workers/wrangler/configuration/#generated-wrangler-configuration" `); expect(std).toMatchObject(NO_LOGS); @@ -253,7 +260,14 @@ describe("config findWranglerConfig()", () => { expect(normalizeString(`${error}`)).toMatchInlineSnapshot(` "Error: Found both a user configuration file at "bar/foo/wrangler.toml" and a deploy configuration file at "bar/.wrangler/deploy/config.json". - But these do not share the same base path so it is not clear which should be used." + But these do not share the same base path so it is not clear which should be used. + + A deploy configuration file is generated by a build tool to redirect Wrangler to the configuration it generated. + It is only applied when it sits alongside the user configuration file, which here would be "bar/foo/.wrangler/deploy/config.json". + + Please either delete "bar/.wrangler/deploy/config.json" if it is left over from a previous build, + or run this command from the directory containing the configuration you want to use. + See https://developers.cloudflare.com/workers/wrangler/configuration/#generated-wrangler-configuration" `); expect(std).toMatchObject(NO_LOGS); });