Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wide-cobras-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: load env before prerender
12 changes: 6 additions & 6 deletions packages/kit/src/core/postbuild/prerender.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ async function prerender({ hash, out, manifest_path, metadata, verbose, env }) {

installPolyfills();

const server = new Server(manifest);
await server.init({
env,
read: (file) => createReadableStream(`${config.outDir}/output/server/${file}`)
});

/** @type {Map<string, string>} */
const saved = new Map();

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

log.info('Prerendering');

const server = new Server(manifest);
await server.init({
env,
read: (file) => createReadableStream(`${config.outDir}/output/server/${file}`)
});

for (const entry of config.prerender.entries) {
if (entry === '*') {
for (const [id, prerender] of prerender_map) {
Expand Down
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The presence of this file alone is the test for if this works or not, right? Can we add a comment to this file explaining that if that’s the case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { env } from '$env/dynamic/private';
import { env as public_env } from '$env/dynamic/public';

if (!env.PRIVATE_DYNAMIC || !public_env.PUBLIC_DYNAMIC) {
// This checks that dynamic env vars are available when prerendering remote functions
// https://github.com/sveltejs/kit/pull/14219
throw new Error('Dynamic environment variables are not set up correctly');
}
Loading