Skip to content

fix: make vite a dynamic import and declare it as optional peer dependency - #259

Closed
so1ve with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-unplugin-solid-dependency
Closed

fix: make vite a dynamic import and declare it as optional peer dependency#259
so1ve with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-unplugin-solid-dependency

Conversation

Copilot AI commented Jul 13, 2026

Copy link
Copy Markdown

unplugin-solid had a static top-level import { version } from "vite" that caused a hard runtime failure in strict dependency environments (Yarn PnP) when consumers weren't using Vite — the module would fail to load even for Rollup/esbuild/webpack users.

Changes

  • src/core/index.ts: Replace static import { version } from "vite" with a dynamic await import("vite") scoped to the Vite-specific config hook where it's actually needed, with a clear error message if the import fails
  • package.json: Declare vite >=4 as an optional peer dependency via peerDependenciesMeta
-import { version } from "vite";
 // ...
 vite: {
   async config(userConfig, { command }) {
     // ...
+    const { version } = await import("vite").catch(() => {
+      throw new Error("[unplugin-solid] Failed to import 'vite'. Make sure 'vite' is installed.");
+    });
     const isViteGreaterThan6 = +version.split(".")[0] >= 6;

@bolt-new-by-stackblitz

Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copilot AI changed the title [WIP] Fix unplugin-solid dependency issue with vite fix: make vite a dynamic import and declare it as optional peer dependency Jul 13, 2026
Copilot finished work on behalf of so1ve July 13, 2026 19:27
Copilot AI requested a review from so1ve July 13, 2026 19:27
@so1ve
so1ve marked this pull request as ready for review July 13, 2026 19:33
@so1ve so1ve closed this in #260 Jul 14, 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.

unplugin-solid tried to access vite, but it isn't declared in its dependencies

2 participants