#Typed Router not working in Bun monorepo - useRoute returns generic types

5 messages · Page 1 of 1 (latest)

slate zealot
#

Hey! I'm having an issue with experimental: { typedPages: true } in a Bun monorepo setup.

Problem:
useRoute()⁩ should be typed as:

⁨```ts
function useRoute<Name extends keyof RouteNamedMap>(_name?: Name): RouteLocationNormalizedLoaded<Name>

But instead I get:

⁨```ts
function _useRoute<Name extends string | symbol>(_name?: Name): RouteLocationNormalizedLoadedGeneric
```⁩
So route.params.itemShortId is untyped.

Setup:

Nuxt 4.3.0
Bun 1.3.6 (monorepo with workspaces)
experimental: { typedPages: true } enabled
.nuxt/types/typed-router.d.ts is correctly generated with RouteNamedMap
Root cause (I think):
In .nuxt/tsconfig.json, Nuxt generates this path mapping:


"vue-router/auto-routes": [
  "../../../node_modules/.bun/[email protected]+.../vue-router/vue-router-auto-routes"
]
This points to vue-router's stub file (vue-router-auto-routes.d.ts) which only exports routes: any[].

The module augmentation chain seems broken:

typed-router.d.ts augments 'vue-router/auto-routes' with RouteNamedMap ✅
unplugin-vue-router/client.d.ts imports RouteNamedMap from 'vue-router/auto-routes' to augment vue-router's TypesConfig ❌ (doesn't resolve correctly?)
What I've tried:

Removing the path mapping → useRoute becomes any
Pointing the path mapping to ./types/typed-router → same issue
Creating a bridge .d.ts file with triple-slash references → no effect
Has anyone got typed routes working in a Bun monorepo? Any ideas? 🙏
old saddleBOT
#

Hi @slate zealot. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

There’s not enough information in the knowledge sources to fully diagnose this specific Bun + monorepo + typedPages issue, but there are a few relevant hints and limitations worth calling out.

From the sources:

  • Nuxt’s typed pages are powered by unplugin-vue-router under the hood and are still marked experimental. [Type-safe routing]
  • Nuxt generates a typed-router.d.ts file and wires it into its TS config / project references. There has been work to make sure the path to typed-router.d.ts is resolved consistently and added as a TS project reference. [typed-router path]
  • There are known issues around TypeScript project references and global/auto-imported types in Nuxt 4.3.0, especially in monorepo setups and with nuxt typecheck. These were traced to how the root tsconfig.json uses project references and how TypeScript resolves declarations across them. [TS type detection; typecheck fails]
  • One temporary workaround for type resolution problems in 4.3.x was to revert the root tsconfig.json to simply extend .nuxt/tsconfig.json instead of using project references, which made vue-tsc resolve global declarations correctly again. [TS type detection]

However, the knowledge sources:

  • Do not mention Bun’s .bun-scoped paths resolution for vue-router/auto-routes.
  • Do not describe or confirm any fix/workaround specifically for useRoute falling back to RouteLocationNormalizedLoadedGeneric in a Bun monorepo.
  • Do not document how to override the vue-router/auto-routes path mapping in a Bun workspace so that unplugin-vue-router/client.d.ts correctly sees your RouteNamedMap.
#

Given those limits, all I can say with confidence from the sources is:

  1. Your observation that typed-router.d.ts augments 'vue-router/auto-routes' and that unplugin-vue-router/client.d.ts then imports RouteNamedMap from there matches how typed routing is supposed to work. [TYPESAFE routing]
  2. Nuxt 4.3.0 has had type-resolution regressions in more complex setups (monorepos, Bun, project references). Some of these were fixed or worked around by adjusting the root tsconfig to avoid project-reference build mode for vue-tsc. [TS type detection; typecheck fails]
  3. There is no explicit documentation in the provided sources about the vue-router/auto-routes path mapping being wrong under Bun, nor about a confirmed fix for that mapping.

Because of that, I can’t reliably suggest a Bun-specific or monorepo-specific configuration change beyond what you’ve already tried, and I can’t confirm whether this is a Nuxt bug, a Bun resolver quirk, or an interaction between the two.

Given the patterns in the linked issues, the most likely next steps (based on what Nuxt maintainers usually ask for) would be:

  • Providing a minimal reproduction repo so the Nuxt team can see how Bun’s .bun path mapping is interacting with vue-router/auto-routes. [Bun-only issue]
  • Opening or commenting on a Nuxt GitHub issue describing:
    • Nuxt 4.3.0
    • Bun 1.3.6 in a monorepo
    • experimental.typedPages: true
    • The generated paths entry for "vue-router/auto-routes" pointing into .bun/.../vue-router-auto-routes.d.ts
    • The resulting generic useRoute signature.
#

I’m sorry I can’t give you a concrete working configuration from these sources alone; the knowledge provided simply doesn’t include a confirmed solution for this exact Bun + monorepo + typed router scenario.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: