Skip to content

Avoid leaking Vite plugin types#1218

Closed
peterp wants to merge 7 commits into
mainfrom
fix/vite-plugin-type-leak
Closed

Avoid leaking Vite plugin types#1218
peterp wants to merge 7 commits into
mainfrom
fix/vite-plugin-type-leak

Conversation

@peterp

@peterp peterp commented Jun 1, 2026

Copy link
Copy Markdown
Member

Problem

Some projects can end up with two physical copies of Vite in node_modules. When that happens, TypeScript may see RedwoodSDK's Vite plugin type and the app's Vite plugin type as two different things. The app then gets a confusing defineConfig() type error, even though the plugins work at runtime.

Reported by @quantizor in #1112.

Solution

This PR follows the dependency-layout fix suggested in #1112: make @vitejs/plugin-react an optional peer dependency instead of a runtime dependency of rwsdk. That lets the app own the React Vite plugin and its Vite peer, avoiding an extra Vite copy under rwsdk/node_modules.

Technical Summary

  • Move @vitejs/plugin-react from dependencies to optional peerDependencies and devDependencies in sdk/package.json.
  • Lazy-load @vitejs/plugin-react only when RedwoodSDK needs to include the default React Vite plugin.
  • Keep the typed redwoodPlugin() return type as Promise<InlineConfig["plugins"]>, addressing the review concern about any[].
  • Add @vitejs/plugin-react to the starter app so generated apps satisfy the optional peer.
  • Default to including RedwoodSDK's React plugin unless users explicitly pass includeReactPlugin: false.

Closes #1112

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 1, 2026

Copy link
Copy Markdown

Deploying redwood-sdk-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: daf65da
Status:🚫  Build failed.

View logs

Reported-by: Evan Jacobs <570070+quantizor@users.noreply.github.com>
@peterp peterp force-pushed the fix/vite-plugin-type-leak branch from 383b64d to 4b4e8f0 Compare June 1, 2026 10:26
Comment thread sdk/src/vite/redwoodPlugin.mts Outdated
export const redwoodPlugin = async (
options: RedwoodPluginOptions = {},
): Promise<InlineConfig["plugins"]> => {
): Promise<any[]> => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@peterp Can't we import type InlineConfig and then use it here? any casting for our main redwoodPlugin export is quite a change.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah! I don't know why the inference picked this shape.

@peterp peterp closed this Jun 9, 2026
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.

redwood() return type conflicts with project Vite types (duplicate PluginOption)

2 participants