plugin-vite does not declare vite as a runtime dependency
- Dominant language
- TypeScript
- Stars
- 7.1k
- Forks
- 641
- Avg merge
- 3d 1h
- Merged PRs (30d)
- 30
Description
## Pre-flight checklist
- [x] I have read the [contribution documentation](https://github.com/electron/forge/blob/main/CONTRIBUTING.md) for this project.
- [x] I agree to follow the [code of conduct](https://github.com/electron/electron/blob/main/CODE_OF_CONDUCT.md) that this project uses.
- [x] I have searched the issue tracker for a matching bug.
## Forge version
7.11.2
## Electron version
42.3.2
## Operating system
macOS 26.5.2 arm64
## Expected behavior
`@electron-forge/plugin-vite` can be loaded in a project whose `node_modules` uses a strict, non-hoisted layout.
## Actual behavior
The package requires Vite at runtime but declares it only in `devDependencies`.
These files all `require('vite')` at runtime:
- `dist/VitePlugin.js`
- `dist/ViteConfig.js`
- `dist/config/vite.main.config.js`
- `dist/config/vite.preload.config.js`
- `dist/config/vite.renderer.config.js`
With a hoisted `node_modules`, this resolves by accident through the application's own copy of Vite. With a strict layout it does not resolve at all, the plugin cannot be loaded, and `electron-forge start` and `electron-forge package` both fail.
Reproduced with Bun 1.4.0 isolated installs:
```text
$ node -e "require('@electron-forge/plugin-vite')"
Error: Cannot find module 'vite'
Require stack:
- .../@electron-forge/plugin-vite/dist/VitePlugin.js
```
```text
$ bun -e "require('@electron-forge/plugin-vite')"
error: Cannot find package 'vite' from
'.../@electron-forge/plugin-vite/dist/VitePlugin.js'
```
Bun's isolated linker symlinks each package into a content-addressed store outside the project. Node and Bun resolve a symlink to its real path before they walk parent directories, so the resolution chain starts in the store and never reaches the application's root `node_modules`. The `install.hoist` fallback directory, `hoistPattern` and `publicHoistPattern` do not change this; all three were tried. The `globalStore` setting does not change it either. The same reasoning applies to pnpm and to Yarn PnP.
## Steps to reproduce
1. Create an empty directory with this `package.json`:
```json
{
"name": "repro",
"private": true,
"devDependencies": {
"@electron-forge/plugin-vite": "7.11.2",
"vite": "^8.0.16"
}
}
```
2. Add this `bunfig.toml`:
```toml
[install]
linker = "isolated"
```
3. Run `bun install`.
4. Run `node -e "require('@electron-forge/plugin-vite')"`.
## Suggested fix
Add a peer dependency on Vite in `packages/plugin/vite/package.json`:
```json
"peerDependencies": {
"vite": ">=5"
}
```
A peer dependency rather than a regular dependency, because the application owns the Vite version. Forge reads the user's `vite.*.config.ts` through `loadConfigFromFile`, so a pinned regular dependency would install a second Vite and parse the config with the wrong major. `vite` stays in `devDependencies` for the package's own tests.
This is also constraint-clean: `enforceConsistentDependenciesAcrossTheProject` in `yarn.config.cjs` skips `peerDependencies` and already exempts `vite` by name.
Contributor guide
Research direction
Start with packages/plugin/vite/package.json and inspect the existing dependency declarations, then check the peer-dependency constraint handling in yarn.config.cjs. Reproduce the require failure with the Bun isolated linker, add the requested Vite peer declaration, and verify that @electron-forge/plugin-vite loads successfully without relying on a hoisted application dependency.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript, vite
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 90/100