Showing Default Error Component in Electron when using with react
Describe the bug
i routes.tsx component inside the render folder i.e., src/render/src/routes.tsx i am using electron vite config
Throws the above Not found error for some reason
Got this error in the log
♻️ Generating routes... [Error: ENOENT: no such file or directory, scandir '/home/sudhakark/work/zero-lens/src/routes'] { errno: -2, code: 'ENOENT', syscall: 'scandir', path: '/home/user/work/App/src/routes' }
i understand that the rotes is not present in the above path location(home/user/work/App/src/routes), it is actually present inside the home/user/work/App/src/render/src/routes.tsx, however i truly believe that location should be configurable as in this case while using with electron with react, the routes are only for the frontend i.e., so i think it is only logical to put inside the render folder as src/render/src/routes.tsx
Your Example Website or App
Throws the above "Not found" error
Steps to Reproduce the Bug or Issue
you can use electron vite boilerplate -> https://github.com/electron-vite/electron-vite-react
and declare the routes inside the src/render/
Expected behavior
Got this error in the log
♻️ Generating routes... [Error: ENOENT: no such file or directory, scandir '/home/sudhakark/work/zero-lens/src/routes'] { errno: -2, code: 'ENOENT', syscall: 'scandir', path: '/home/user/work/App/src/routes' }
i understand that the rotes is not present in the above path location(home/user/work/App/src/routes), it is actually present inside the home/user/work/App/src/render/src/routes.tsx, however i truly believe that location should be configurable as in this case while using with electron with react, the routes are only for the frontend i.e., so i think it is only logical to put inside the render folder as src/render/src/routes.tsx
Screenshots or Videos
Throws the above Not found error for some reason
Platform
- OS: [e.g. macOS, Windows, Linux] ->Linux
- Browser: [e.g. Chrome, Safari, Firefox] ->Electron uses Chromium internally
- Version: [e.g. 91.1] -> not sure on this one
Additional context
No response
please provide a complete example repo
I had a similar problem recently. unlike you, i'm using file based routing and using the hash router instead of browser router solved my issue (as mentioned here: https://github.com/TanStack/router/discussions/835).
it is hard to tell without seeing the code but ♻️ Generating routes... part seems like an action taken by TanStackRouterVite() plugin which is related to file based routing. taking a look at docs might help : https://tanstack.com/router/v1/docs/framework/react/guide/file-based-routing#configuration
Adding a notice related to using routers in Electron apps to the docs might be useful. Also this error message (Not found) is so generic that it took me while to understand 😄
I think even in my case this is the only issue as we use a hash router. Thanks a lot for the heads-up
For some reason my tsr.config.json file was not correctly defining the relative path, I just deleted the file and passed the path to the plugin wrapping it in the path definition function
import * as path from 'node:path';
TanStackRouterVite({
routesDirectory: path.join(__dirname, './routes'),
generatedRouteTree: path.join(__dirname, './src/app/ui/routeTree.gen.ts'),
routeFileIgnorePrefix: '-',
quoteStyle: 'single',
})
if this helps I'd be glad