T
TanStack•6mo ago
noble-gold

Cannot access 'routeTree' before initialization

Hi all. Not sure if anybody else has a problem with this or if it's mean to be like this but I keep on getting this error on any change in the codebase. The question is did I do something un-correctly? I've got a router context that I'm using for the routes - and I noted the error when I create the rootRouteWithContext. Any ideas?
3 Replies
deep-jade
deep-jade•6mo ago
what exactly does not work? please provide a minimal complete example
noble-gold
noble-goldOP•6mo ago
I'm trying to reproduce the problem in StackBlitz with no luck. Here's the link for it but I guess it's something in the project on my side. I haven't added Mobx in the example and the API calls since they're behind a wall. https://stackblitz.com/edit/vitejs-vite-mezbgbbh?file=src%2Fmain.tsx Will try to figure this one out. But what happens is that it throws this error when I make a change in the beforeUpload ( just threw a console log into it ) and HMR kicks in:
Uncaught ReferenceError: Cannot access 'routeTree' before initialization
at main.tsx:22:3
Uncaught ReferenceError: Cannot access 'routeTree' before initialization
at main.tsx:22:3
Nejc Vukovic
StackBlitz
Tanstack-Router-Playground - StackBlitz
Next generation frontend tooling. It's fast!
noble-gold
noble-goldOP•6mo ago
I think I get it now... It has something to do with: https://github.com/TanStack/router/issues/539 Is the route generation not done yet when HMR tries to reload? Could that be it? Since I'm checking if modules are present in the context in the beforeLoad -> if not I do a API call for the data. Or maybe the Mobx. Will send updates 😉
GitHub
ReferenceError: can't access lexical declaration route before ini...
Describe the bug When updating any component that belongs to a route (for me /pages), the Router cannot update the page as it gets an error: ReferenceError: can't access lexical declaration ...

Did you find this page helpful?