@@ -68,6 +68,10 @@ export function prerenderPlugin({ prerenderScript, renderTarget, additionalPrere
6868 const preloadHelperId = 'vite/preload-helper' ;
6969 const preloadPolyfillId = 'vite/modulepreload-polyfill' ;
7070
71+ // PNPM, Yalc, and anything else utilizing symlinks mangle the file
72+ // path a bit so we need a minimal, fairly unique ID to check against
73+ const tmpDirId = 'headless-prerender' ;
74+
7175 /**
7276 * From the non-external scripts in entry HTML document, find the one (if any)
7377 * that provides a `prerender` export
@@ -231,16 +235,14 @@ export function prerenderPlugin({ prerenderScript, renderTarget, additionalPrere
231235 ) ;
232236 let htmlDoc = htmlParse ( tpl ) ;
233237
234- // Workaround for PNPM mangling file paths with their symlinks
235- const tmpDirRelative = path . join (
238+ // Create a tmp dir to allow importing & consuming the built modules,
239+ // before Rollup writes them to the disk
240+ const tmpDir = path . join (
241+ viteConfig . root ,
236242 'node_modules' ,
237243 'vite-prerender-plugin' ,
238- 'headless-prerender' ,
244+ tmpDirId
239245 ) ;
240-
241- // Create a tmp dir to allow importing & consuming the built modules,
242- // before Rollup writes them to the disk
243- const tmpDir = path . join ( viteConfig . root , tmpDirRelative ) ;
244246 try {
245247 await fs . rm ( tmpDir , { recursive : true } ) ;
246248 } catch ( e ) {
@@ -298,7 +300,7 @@ export function prerenderPlugin({ prerenderScript, renderTarget, additionalPrere
298300 ` . replace ( / ^ \t { 5 } / gm, '' ) ;
299301
300302 const stack = StackTraceParse ( e ) . find ( ( s ) =>
301- s . getFileName ( ) . includes ( tmpDirRelative ) ,
303+ s . getFileName ( ) . includes ( tmpDirId ) ,
302304 ) ;
303305
304306 const sourceMapContent = prerenderEntry . map ;
0 commit comments