Skip to content

fix: warn when existing vite.config.ts is missing cloudflare plugin on deploy#315

Merged
james-elicx merged 2 commits intomainfrom
fix/issue-312-deploy-vite-config-prereqs
Mar 7, 2026
Merged

fix: warn when existing vite.config.ts is missing cloudflare plugin on deploy#315
james-elicx merged 2 commits intomainfrom
fix/issue-312-deploy-vite-config-prereqs

Conversation

@james-elicx
Copy link
Collaborator

Summary

Fixes #312.

Three blockers were reported in the npm create next-appnpx vinext init → deploy flow:

  1. CLOUDFLARE_API_TOKEN permissions not documented
  2. account_id missing from generated wrangler.jsonc, with no docs on how to supply it
  3. Build fails with could not resolve virtual:vinext-rsc-entry because vinext init generates a minimal local-dev vite.config.ts without @cloudflare/vite-plugin, and vinext deploy silently skips config generation when the file already exists

Changes

  • deploy.ts — add viteConfigHasCloudflarePlugin(): when vinext deploy detects an existing vite.config.ts that doesn't import @cloudflare/vite-plugin, it now emits a clear warning with the exact config fix instead of silently proceeding to a broken build
  • README.md — add a "Prerequisites" section to the Cloudflare Workers deployment docs covering: wrangler login vs CLOUDFLARE_API_TOKEN (with correct "Edit Cloudflare Workers" template permissions), and how to supply account_id
  • tests/deploy.test.ts — 7 new unit tests for viteConfigHasCloudflarePlugin()

Testing

pnpm test tests/deploy.test.ts   # 175 tests pass
pnpm test tests/init.test.ts     # 59 tests pass

…n deploy

Closes #312.

- Add `viteConfigHasCloudflarePlugin()` to deploy.ts: when `vinext deploy`
  finds an existing vite.config.ts that doesn't import @cloudflare/vite-plugin,
  it now prints an actionable warning with the exact config fix rather than
  silently proceeding to a broken build.
- Add README prerequisites section to the Cloudflare Workers deploy docs:
  covers wrangler login vs CLOUDFLARE_API_TOKEN (with required permissions)
  and how to supply account_id.
- Add 7 unit tests for `viteConfigHasCloudflarePlugin()`.
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 7, 2026

Open in StackBlitz

npm i https://pkg.pr.new/vinext@315

commit: 65d3a8b

@github-actions
Copy link

github-actions bot commented Mar 7, 2026

Example Preview Production Original
app-router-cloudflare preview production
pages-router-cloudflare preview production
app-router-playground preview production original
realworld-api-rest preview production
nextra-docs-template preview production
benchmarks preview production
hackernews preview production original

@james-elicx james-elicx marked this pull request as ready for review March 7, 2026 14:27
@james-elicx
Copy link
Collaborator Author

/bigbonk review

Copy link
Contributor

@ask-bonk ask-bonk bot left a comment

Choose a reason for hiding this comment

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

Review

Good change — this addresses a real pain point where vinext initvinext deploy silently fails with a cryptic error. The detection function, warning placement, tests, and README additions are all well done.

One bug to fix before merging:

Bug: Pages Router warning shows invalid syntax

In the warning message at deploy.ts:1147-1149, the Pages Router branch produces cloudflare(()) instead of cloudflare():

        cloudflare(${info.isAppRouter ? `{
          viteEnvironment: { name: "rsc", childEnvironments: ["ssr"] },
        }` : "()"}),

When info.isAppRouter is false, the template interpolates () inside the existing cloudflare(...), producing:

cloudflare(()),

That's a JS syntax error. Fix by changing "()" to "":

        cloudflare(${info.isAppRouter ? `{
          viteEnvironment: { name: "rsc", childEnvironments: ["ssr"] },
        }` : ""}),

Or restructure the ternary to include cloudflare(...) in both branches.

Everything else looks good

  • viteConfigHasCloudflarePlugin() — clean heuristic, checks all three config variants, safe default on read errors
  • The guard condition info.hasViteConfig && !viteConfigHasCloudflarePlugin(root) is correct — only fires when a user-supplied config exists but is missing the plugin
  • Tests cover both positive and negative cases across .ts/.js/.mjs, including the exact vinext init-generated config that triggers issue #312
  • README prerequisites section is clear and covers both auth methods and account ID configuration

@ask-bonk
Copy link
Contributor

ask-bonk bot commented Mar 7, 2026

Review posted. Here's a summary:

Reviewed PR #315fix: warn when existing vite.config.ts is missing cloudflare plugin on deploy

The PR is solid overall. It addresses a real UX problem where vinext init generates a minimal vite config without @cloudflare/vite-plugin, and then vinext deploy silently proceeds to a broken build. The fix adds a clear warning with the exact config fix needed.

One bug found: The warning message for Pages Router projects renders cloudflare(()) (a syntax error) instead of cloudflare(). The ternary interpolates "()" inside the existing cloudflare(...) parentheses. Fix: change "()" to "" in the ternary's else branch.

Everything else — the detection function, test coverage (7 new tests), guard condition placement in the deploy flow, and README prerequisites docs — is well done. Requested changes for the syntax bug fix.

github run

@james-elicx
Copy link
Collaborator Author

/bigbonk re-review

Copy link
Contributor

@ask-bonk ask-bonk bot left a comment

Choose a reason for hiding this comment

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

Re-review

The cloudflare(()) bug from the previous review is fixed — the ternary else branch now correctly uses "" (empty string), producing cloudflare() for Pages Router projects.

Everything else remains solid:

  • Detection function — simple string-includes heuristic is the right call here. Covers .ts/.js/.mjs variants, fails safe on read errors (returns true to avoid false warnings), returns false when no config exists at all
  • Guard conditioninfo.hasViteConfig && !viteConfigHasCloudflarePlugin(root) correctly limits the warning to cases where a user-supplied config exists but is missing the plugin. Won't fire when vinext auto-generates the config (since that path writes the plugin)
  • Warning is non-blocking — uses console.warn and continues, which is the right severity for a heuristic check. The user can still proceed if they have an unusual setup
  • Test coverage — 7 tests cover positive/negative cases across all config file variants plus the exact vinext init-generated config that triggers #312
  • README prerequisites — clear, covers both auth methods and account ID

LGTM.

@ask-bonk
Copy link
Contributor

ask-bonk bot commented Mar 7, 2026

Re-review posted and approved. The cloudflare(()) syntax bug from the first review is fixed — the else branch now interpolates an empty string, correctly producing cloudflare() for Pages Router projects. No other issues found. LGTM.

github run

@james-elicx james-elicx merged commit 70b1853 into main Mar 7, 2026
23 checks passed
@james-elicx james-elicx deleted the fix/issue-312-deploy-vite-config-prereqs branch March 7, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Creating and deploying a new project is broken

1 participant