router icon indicating copy to clipboard operation
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'

Open austinm911 opened this issue 1 year ago • 2 comments

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

  1. Add root context
  2. 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

austinm911 avatar Aug 26 '24 06:08 austinm911

I’ve noticed the same issue with splat routes.

lo1tuma avatar Aug 26 '24 09:08 lo1tuma

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

image

removing the beforeLoad prevents the error as well

uncvrd avatar Aug 28 '24 17:08 uncvrd