Skip to content

Commit c5f7139

Browse files
fix: load env before prerender (#14219)
* fix: load env before prerender * chore: changeset * chore: add test * chore: add comment in test file Co-authored-by: Rich Harris <richard.a.harris@gmail.com> * simplify --------- Co-authored-by: Rich Harris <richard.a.harris@gmail.com> Co-authored-by: Rich Harris <rich.harris@vercel.com>
1 parent 1f2b69c commit c5f7139

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

.changeset/wide-cobras-yell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
fix: load env before prerender

packages/kit/src/core/postbuild/prerender.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ async function prerender({ hash, out, manifest_path, metadata, verbose, env }) {
125125

126126
installPolyfills();
127127

128+
const server = new Server(manifest);
129+
await server.init({
130+
env,
131+
read: (file) => createReadableStream(`${config.outDir}/output/server/${file}`)
132+
});
133+
128134
/** @type {Map<string, string>} */
129135
const saved = new Map();
130136

@@ -503,12 +509,6 @@ async function prerender({ hash, out, manifest_path, metadata, verbose, env }) {
503509

504510
log.info('Prerendering');
505511

506-
const server = new Server(manifest);
507-
await server.init({
508-
env,
509-
read: (file) => createReadableStream(`${config.outDir}/output/server/${file}`)
510-
});
511-
512512
for (const entry of config.prerender.entries) {
513513
if (entry === '*') {
514514
for (const [id, prerender] of prerender_map) {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { env } from '$env/dynamic/private';
2+
import { env as public_env } from '$env/dynamic/public';
3+
4+
if (!env.PRIVATE_DYNAMIC || !public_env.PUBLIC_DYNAMIC) {
5+
// This checks that dynamic env vars are available when prerendering remote functions
6+
// https://github.com/sveltejs/kit/pull/14219
7+
throw new Error('Dynamic environment variables are not set up correctly');
8+
}

0 commit comments

Comments
 (0)