T
TanStack12mo ago
compatible-crimson

Path aliases with tanstack start? (SOLVED)

Hello! im trying to prerender my app using tanstack start, i added the config found in the example:
import { defineConfig } from '@tanstack/start/config'

export default defineConfig({
deployment: {
prerender: {
routes: ['/'],
crawlLinks: true,
},
},
})
import { defineConfig } from '@tanstack/start/config'

export default defineConfig({
deployment: {
prerender: {
routes: ['/'],
crawlLinks: true,
},
},
})
But ran into a problem with path aliases. I found this guide that says we can add a plugin to all routers in vinxi to get the same path aliases from tsconfig: https://vinxi.vercel.app/guide/aliases.html but i believe its not possible to use this with tanstack start at the moment? is there an easier way to prerender my app built with tanstack router? i looked into solutions like react-snap but seem unmaintained
Path Aliases | Vinxi
Vinxi Documentation
15 Replies
like-gold
like-gold12mo ago
Have you tried adding the vite-tsconfig-paths plugin and determined it didn't work? It seems to work for me:
// app.config.ts
import { defineConfig } from '@tanstack/start/config';
import tsConfigPaths from 'vite-tsconfig-paths';

export default defineConfig({
vite: {
plugins: () => [tsConfigPaths()],
},
});
// app.config.ts
import { defineConfig } from '@tanstack/start/config';
import tsConfigPaths from 'vite-tsconfig-paths';

export default defineConfig({
vite: {
plugins: () => [tsConfigPaths()],
},
});
compatible-crimson
compatible-crimsonOP12mo ago
No sorry it's my first time using vinxi and I'm not really sure what I'm doing, I'll try that when I get home, thanks! @icanflyit Did you actually get this to work? it seems like it does but im getting the same error about imports when trying to run it
like-gold
like-gold12mo ago
It works fine for me, how is your tsconfig configured?
dependent-tan
dependent-tan12mo ago
I got it to work by doing what icanflyit recommended in the app.config.ts and then adding this to my tsconfig:
"compilerOptions": {
"baseUrl": ".",
"paths": {
"~/*": ["./app/*"]
},
},
"compilerOptions": {
"baseUrl": ".",
"paths": {
"~/*": ["./app/*"]
},
},
like-gold
like-gold12mo ago
this is what my tsconfig looks like too
compatible-crimson
compatible-crimsonOP12mo ago
mine too, thats weird, and i have
"paths": {
"@/*": ["src/*"],
}
"paths": {
"@/*": ["src/*"],
}
also its working with vite
dependent-tan
dependent-tan12mo ago
Do you have the base url part
compatible-crimson
compatible-crimsonOP12mo ago
yea ./
dependent-tan
dependent-tan12mo ago
maybe you can try this: "baseUrl": ".", "paths": { "~/": ["./src/"] }, This is actually what my app.config.ts looks like:
import { defineConfig } from '@tanstack/start/config'
import tsConfigPaths from 'vite-tsconfig-paths'

export default defineConfig({
vite: {
plugins: () => [
tsConfigPaths({
projects: ['./tsconfig.json']
})
]
}
})
import { defineConfig } from '@tanstack/start/config'
import tsConfigPaths from 'vite-tsconfig-paths'

export default defineConfig({
vite: {
plugins: () => [
tsConfigPaths({
projects: ['./tsconfig.json']
})
]
}
})
compatible-crimson
compatible-crimsonOP12mo ago
that was it! i had to add the projects path in tsconfigspath plugin thank you!
dependent-tan
dependent-tan12mo ago
Nice! also there are dedicated start channels if you browse the channels. You'll see I put the same question in there lol
genetic-orange
genetic-orange12mo ago
We should add this to the docs
compatible-crimson
compatible-crimsonOP12mo ago
Oh! i didnt know there was a specific channel for start, i pinned it now, thanks! Yea defnintly would be nice if it was in the docs!
harsh-harlequin
harsh-harlequin12mo ago
can you provide a PR to the docs?
extended-salmon
extended-salmon12mo ago
TanStack | High Quality Open-Source Software for Web Developers
Headless, type-safe, powerful utilities for complex workflows like Data Management, Data Visualization, Charts, Tables, and UI Components.
From An unknown user
From An unknown user

Did you find this page helpful?