Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/config-conflict-error-guidance.md
Original file line number Diff line number Diff line change
@@ -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.
16 changes: 12 additions & 4 deletions packages/workers-utils/src/config/config-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Comment on lines +160 to +161

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Deeper configurations remain unusable

When the wanted configuration is below the unwanted one, run this command repeats the same conflict. Both find.file searches walk upward, so the deeper directory still discovers the unwanted ancestor.

Prompt for agents
The conflict guidance does not resolve every path ordering. Both the user configuration lookup in findWranglerConfig and the deploy configuration lookup in findRedirectedWranglerConfig search upward. Running from a deeper desired configuration's directory therefore continues to find the unwanted configuration in an ancestor. Update the guidance to offer a remedy that works when the desired configuration is deeper, such as an applicable explicit configuration option or removing, moving, or regenerating the conflicting ancestor file. Add tests for selecting each file in both existing path-ordering scenarios.
Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

See https://developers.cloudflare.com/workers/wrangler/configuration/#generated-wrangler-configuration
`,
{ telemetryMessage: false }
);
Expand Down
18 changes: 16 additions & 2 deletions packages/workers-utils/tests/config/findWranglerConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
});
Expand Down
Loading