Should Start docs document that import.meta.dirname changes during prerender? #7518
Replies: 1 comment
|
Yes, this is an important nuance with Nitro-backed static prerendering that catches people off guard. Why this happensDuring static prerendering, Nitro does not execute your raw TypeScript files in-place. Instead, it:
Because Recommended approaches
Opening a PR to note in the TanStack Start Prerendering / Nitro guide that server modules execute from the compiled output directory during prerender would definitely help prevent this confusion. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I ran into a confusing path-resolution issue with TanStack Start + Nitro prerendering.
In server code, I used
import.meta.dirnameto resolve a project-relative directory:This works in the dev environment, but during prerendering, the module is executed from the built server output (
.output/server/_ssr), soimport.meta.dirnameno longer points to the expected path.This could be fixed by resolving with
process.cwd():Should the Static Prerendering docs mention that server code executed during prerendering runs from generated output, so
import.meta.dirnameshould not be assumed to refer to the original file path?All reactions