Skip to content

[wrangler] Fix autoconfig for Vite projects without a config file#14074

Merged
MattieTK merged 1 commit into
mainfrom
fix/autoconfig-vite-no-config-file
May 28, 2026
Merged

[wrangler] Fix autoconfig for Vite projects without a config file#14074
MattieTK merged 1 commit into
mainfrom
fix/autoconfig-vite-no-config-file

Conversation

@MattieTK

Copy link
Copy Markdown
Member

wrangler setup crashed with "Could not find Vite config file to modify" for Vite projects that have no vite.config.js or vite.config.ts. Vite does not require a config file for simple projects, so several create-vite templates omit it entirely.

When no config file exists, autoconfig now creates a minimal one with the Cloudflare plugin already configured. isConfigured() also returns false instead of throwing.

The fix is scoped to the Vite framework class only. Other frameworks that use the shared transformViteConfig utility (React Router, TanStack) are unaffected -- they always have a config file, and the existing throw behaviour is correct for them.

Affected templates (6 of 16): vanilla, vanilla-ts, react-swc, react-swc-ts, lit, lit-ts


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: this is a bug fix to existing behaviour, no new user-facing configuration
Known issue: create-vite --template solid detected as Static instead of Vite

@netlify/build-info correctly identifies plain Solid projects as solid-js (distinct from solid-start). However, wrangler's allKnownFrameworks list has solid-start but not solid-js, so getFrameworkClassInstance falls back to the Static handler. This means plain Solid SPAs get assets.directory without not_found_handling: "single-page-application", which would cause 404s on client-side routes.

This is a separate issue from the config file fix in this PR. A follow-up could add fallback logic in the autoconfig layer: when an unknown framework is detected but the project has vite as a dependency and uses vite build, route it through the Vite handler instead of Static.

Vite projects scaffolded without a vite.config file (e.g. create-vite
vanilla, react-swc, lit templates) failed with 'Could not find Vite
config file to modify'.

When no config file exists, autoconfig now generates a minimal one with
the Cloudflare plugin already wired in. The Vite.isConfigured() method
also returns false instead of throwing in this case.

The fix is scoped to the Vite framework class. Other frameworks that use
the shared vite-config utilities (React Router, TanStack) still get the
existing throw behaviour, which is correct for them.
@MattieTK MattieTK requested a review from workers-devprod as a code owner May 27, 2026 23:26
@changeset-bot

changeset-bot Bot commented May 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: fbac515

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
wrangler Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-pool-workers Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk May 27, 2026
@workers-devprod workers-devprod requested review from a team and ascorbic and removed request for a team May 27, 2026 23:27
@workers-devprod

workers-devprod commented May 27, 2026

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

@ask-bonk

ask-bonk Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

React Router and TanStack both call transformViteConfig directly without a hasViteConfig guard — but as the PR description says, these frameworks always ship with config files (they're part of the framework scaffolding), so the existing throw behavior in getViteConfigPath is appropriate for them.

Now I have a thorough understanding. Let me check one more thing — the changeset file references only wrangler, which is correct since all changed files are in the wrangler package. The changeset-bot message about 3 packages is likely due to other changesets on the branch or pre-existing changesets, not this PR's changeset.

Let me look at one potential issue more carefully — the dryRun test:

In the dry-run test (line 89-105), dryRun: true means neither installCloudflareVitePlugin nor createViteConfig is called. The test asserts no config file is created AND the correct wranglerConfig is returned. But notice that installPackages is still mocked via vi.spyOn in beforeEach. Even if dryRun weren't guarding the call, the mock would prevent real installation. This is correct test structure.

However, I notice one thing: the test at line 89 does NOT mock installCloudflareVitePlugin (unlike the vike test which uses vi.mock). The vite test relies on the vi.spyOn(cliPackages, "installPackages") mock to catch package installs. Since installCloudflareVitePlugin internally calls installPackages, the spy would catch it. And with dryRun: true, installCloudflareVitePlugin isn't called at all. This is fine.

I'm satisfied with my review. The code changes are clean, correct, and well-scoped. The logic is sound:

  1. isConfigured() now gracefully returns false instead of throwing when no config exists
  2. configure() creates a minimal config file when none exists, using the correct extension
  3. The dryRun guard correctly prevents both installation and file creation
  4. Tests cover the main scenarios adequately
  5. The changeset is correct

LGTM

github run

@github-actions

Copy link
Copy Markdown
Contributor

✅ All changesets look good

@pkg-pr-new

pkg-pr-new Bot commented May 27, 2026

Copy link
Copy Markdown
create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@14074

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/@cloudflare/deploy-helpers@14074

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@14074

miniflare

npm i https://pkg.pr.new/miniflare@14074

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@14074

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@14074

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@14074

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@14074

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@14074

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@14074

wrangler

npm i https://pkg.pr.new/wrangler@14074

commit: fbac515

@dario-piotrowicz dario-piotrowicz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

I also prefer this simpler PR for fixing this compared to #14073 (which is anyways still in draft)

I think that anyways some aspects of 14073 are however good and should be still included (as a followup) such as checking whether the vite config file is cjs.

@workers-devprod workers-devprod left a comment

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.

Codeowners reviews satisfied

@github-project-automation github-project-automation Bot moved this from Untriaged to Approved in workers-sdk May 28, 2026
@MattieTK MattieTK merged commit 37176e5 into main May 28, 2026
65 of 66 checks passed
@github-project-automation github-project-automation Bot moved this from Approved to Done in workers-sdk May 28, 2026
@MattieTK MattieTK deleted the fix/autoconfig-vite-no-config-file branch May 28, 2026 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants