@@ -254,13 +254,6 @@ async function renderComponentToSSR(
254254) : Promise < { html : string } > {
255255 const viteServer = ctx . project . vite ;
256256
257- // vite doesn't replace import.meta.env with hardcoded values so we need to do it manually
258- for ( const [ key , value ] of Object . entries ( viteServer . config . env ) ) {
259- // biome-ignore lint/style/noNonNullAssertion: it's always defined
260- viteServer . config . define ! [ `__vite_ssr_import_meta__.env.${ key } ` ] =
261- JSON . stringify ( value ) ;
262- }
263-
264257 const qwikModule = await viteServer . ssrLoadModule ( "@builder.io/qwik" ) ;
265258 const { jsx } = qwikModule ;
266259 const jsxElement = jsx ( Component , props ) ;
@@ -291,6 +284,13 @@ const renderSSRCommand: ComponentFormat = async (
291284 const absoluteComponentPath = resolve ( projectRoot , componentPath ) ;
292285
293286 const viteServer = ctx . project . vite ;
287+ // vite doesn't replace import.meta.env with hardcoded values so we need to do it manually
288+ for ( const [ key , value ] of Object . entries ( viteServer . config . env ) ) {
289+ // biome-ignore lint/style/noNonNullAssertion: it's always defined
290+ viteServer . config . define ! [ `__vite_ssr_import_meta__.env.${ key } ` ] =
291+ JSON . stringify ( value ) ;
292+ }
293+
294294 const componentModule = await viteServer . ssrLoadModule (
295295 absoluteComponentPath ,
296296 ) ;
@@ -318,6 +318,12 @@ const renderSSRLocalCommand: LocalComponentFormat = async (
318318) => {
319319 try {
320320 const viteServer = ctx . project . vite ;
321+ // vite doesn't replace import.meta.env with hardcoded values so we need to do it manually
322+ for ( const [ key , value ] of Object . entries ( viteServer . config . env ) ) {
323+ // biome-ignore lint/style/noNonNullAssertion: it's always defined
324+ viteServer . config . define ! [ `__vite_ssr_import_meta__.env.${ key } ` ] =
325+ JSON . stringify ( value ) ;
326+ }
321327
322328 // Create a modified version of the test file without vitest imports
323329 const { readFileSync, writeFileSync, unlinkSync } = await import ( "node:fs" ) ;
0 commit comments