Missing vite as optional peer dependency
envgap__vuejs__router-2711
01 / FAILURE SIGNATURE
As reported upstream
../node_modules/.pnpm/@vue+compiler-core@3.5.34/node_modules/@vue/compiler-core/dist/compiler-core.d.ts:3:127 - error TS2307: Cannot find module '@babel/types' or its corresponding type declarations.
Not a benchmark task.
- In a clean container the reported failure did not reproduce, or the known fix did not make the project run.
02 / ENVIRONMENT RECIPE
- Base commit
ddd20c33a582bdcc6daececd5e2cebe414e366a1- Manifest
packages/router/package.json- Reproduce
Awaiting issue-specific recipe- Run under trace
Awaiting a meaningful runtime command
03 / ORIGINAL ISSUE TEXT
vuejs/router #2711 · read the original issue
### Reproduction
https://github.com/ForgottenR/vue-router-showcase
### Steps to reproduce the bug
Clone https://github.com/ForgottenR/vue-router-showcase, run `pnpm install`, and then run `pnpm typecheck` from inside the `app` directory.
Note: The `main` branch shows a typical typecheck error that may happen in a mono repo. But the error requires the hoisted package to have a specific layout, which is not stable and doesn't always happen (should happen if `node_modules` folders are all newly created though). The `non-hoisted` branch uses a more strict pnpm setting with `hoisted: false` which doesn't need the hoisted package confliction and is more clear on the root cause.
### Expected behavior
There should be no type errors.
### Actual behavior
A type error similar to the following
`main` branch:
```
$ pnpm typecheck
$ tsc index.ts --noEmit
index.ts:4:5 - error TS2322: Type 'Plugin<any> | Plugin<any>[]' is not assignable to type 'PluginOption'.
Type 'Plugin<any>' is not assignable to type 'PluginOption'.
Type 'import("/Users/huijieshi/workspace/vue-router-showcase/node_modules/.pnpm/vite@8.0.12_@types+node@25.6.2_yaml@2.8.4/node_modules/vite/dist/node/index").Plugin<any>' is not assignable to type 'import("/Users/huijieshi/workspace/vue-router-showcase/node_modules/.pnpm/vite@6.4.2_@types+node@25.6.2_lightningcss@1.32.0_yaml@2.8.4/node_modules/vite/dist/node/index").Plugin<any>'.
Types of property 'hotUpdate' are incompatible.
Type 'ObjectHook<(this: MinimalPluginContext & { environment: DevEnvironment; }, options: HotUpdateOptions) => void | EnvironmentModuleNode[] | Promise<...>> | undefined' is not assignable to type 'ObjectHook<(this: HotUpdatePluginContext, options: HotUpdateOptions) => void | EnvironmentModuleNode[] | Promise<void | EnvironmentModuleNode[]>> | undefined'.
Type '(this: MinimalPluginContext & { environment: DevEnvironment; }, options: HotUpdateOptions) => void | EnvironmentModuleNode[] | Promise<...>' is not assignable to type 'ObjectHook<(this: HotUpdatePluginContext, options: HotUpdateOptions) => void | EnvironmentModuleNode[] | Promise<void | EnvironmentModuleNode[]>> | undefined'.
Type '(this: MinimalPluginContext & { environment: DevEnvironment; }, options: HotUpdateOptions) => void | EnvironmentModuleNode[] | Promise<...>' is not assignable to type '(this: HotUpdatePluginContext, options: HotUpdateOptions) => void | EnvironmentModuleNode[] | Promise<void | EnvironmentModuleNode[]>'.
The 'this' types of each signature are incompatible.
Type 'HotUpdatePluginContext' is not assignable to type 'MinimalPluginContext & { environment: DevEnvironment; }'.
Type 'HotUpdatePluginContext' is missing the following properties from type 'MinimalPluginContext': error, info, warn, debug, meta
4 let plugin: PluginOption = VueRouter();
~~~~~~
Found 1 error in index.ts:4
[ELIFECYCLE] Command failed with exit code 2.
```
`non-hoisted` branch:
```
$ pnpm typecheck
$ tsc index.ts --noEmit
../node_modules/.pnpm/@vue+compiler-core@3.5.34/node_modules/@vue/compiler-core/dist/compiler-core.d.ts:3:127 - error TS2307: Cannot find module '@babel/types' or its corresponding type declarations.
3 import { Node as Node$1, Identifier, Function, ObjectProperty, BlockStatement as BlockStatement$1, SwitchCase, Program } from '@babel/types';
~~~~~~~~~~~~~~
../node_modules/.pnpm/vue-router@5.0.6_@vue+compiler-sfc@3.5.34_vue@3.5.34_typescript@6.0.3_/node_modules/vue-router/dist/unplugin/vite.d.mts:7:24 - error TS2307: Cannot find module 'vite' or its corresponding type declarations.
7 import * as vite0 from "vite";
~~~~~~
Found 2 errors in 2 files.
Errors Files
1 ../node_modules/.pnpm/@vue+compiler-core@3.5.34/node_modules/@vue/compiler-core/dist/compiler-core.d.ts:3
1 ../node_modules/.pnpm/vue-router@5.0.6_@vue+compiler-sfc@3.5.34_vue@3.5.34_typescript@6.0.3_/node_modules/vue-router/dist/unplugin/vite.d.mts:7
[ELIFECYCLE] Command failed with exit code 2.
```
### Additional information
The root cause of this issue is that in a strict package manager like pnpm, the missing peer dependency declaration would make there no `vite` package to be found in the `node_module` hirarchy from the point of view of the `vue-router` pakackage, thus the `Plugin` type from `vite` cannot be resolved, or resolved to the wrong version sometimes depending on the structure of the pnpm workspace.
It tends to happen only in a mono repo because in a normal repo, the `vite` package is almost always at the root `node_modules`.04 / LABELS
Labels from the report text only; not yet run
No supported category has been assigned.
Label rules and the text that matched
[]