router
router copied to clipboard
Monorepo TS Issue on Routes: The inferred type of 'Route' cannot be named without a reference to '*/@tanstack/react-router/dist/esm/route'
Describe the bug
Noticing this as I build on this monorepo template.
The inferred type of 'Route' cannot be named without a reference to '../../../../node_modules/@tanstack/react-router/dist/esm/route'. This is likely not portable. A type annotation is necessary.
// main.tsx
const router = createRouter({
// ^ error
routeTree,
defaultPreload: 'intent',
defaultStaleTime: 5000,
context: {
user: 'John Doe',
},
})
// routes/index.tsx
export const Route = createFileRoute('/')({
// ^ error
beforeLoad: (context) => {
console.log('beforeLoad', context)
},
component: Home,
})
Your Example Website or App
https://github.com/austinm911/tanstack-monorepo/tree/ts-router-route-bug
Steps to Reproduce the Bug or Issue
- Add root context
- add before load to root index.tsx
Expected behavior
no ts issues
Screenshots or Videos
No response
Platform
├── @tanstack/[email protected]
├── @tanstack/[email protected]
├── @tanstack/[email protected]
├── @types/[email protected]
├── @types/[email protected]
├── @vitejs/[email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]
Additional context
No response
I’ve noticed the same issue with splat routes.
I tried upgrading from
"@tanstack/react-router": "1.45.6"
to
"@tanstack/react-router": "1.51.2"
and just started experiencing this same error in my monorepo too
removing the beforeLoad prevents the error as well