The env object in $env/dynamic/private is empty when accessed from a telefunc function.
Here's an example telefunc function:
import { env } from '$env/dynamic/private';
import { dumpEnvironmentVariables } from '$lib/server/utils';
export async function onGetRemoteSecret() {
dumpEnvironmentVariables(`Telefunc function: onGetRemoteSecret`);
return {
// read secret in idiomatic SvelteKit way
secretFromTelefunc: env.MY_SECRET,
// read secret in Node.js way
secretFromTelefuncProcessEnv: process.env.MY_SECRET
};
}Here's an example load function that works similarly:
import { env } from '$env/dynamic/private';
import { dumpEnvironmentVariables } from '$lib/server/utils';
export const load = () => {
dumpEnvironmentVariables(`Page server load function`);
return {
secretFromLoadFunction: env.MY_SECRET
};
};When running in the dev server this works as expected:

However, using @sveltejs/adapter-node and running the compiled app using node build this is the result:
Things to note:
- Accessing the environment variable in a load function works
- Accessing the environment variable in a telefunc function only works in dev, not in the built application.
- However, the variable is accessible from process.env in both cases (though that isn't the idiomatic way)
Accessing env from $env/dynamic/private should work identicially in dev and prod environments and
especially identically when used in a load function and when accessed from a telefunc function.
On the server, all environment variables in env should be dumped to the console for both the telefunc function and the load function.
Only for the telefunc function:
envin$env/dynamic/privateis empty when accessed from a telefunc function- No value is returned from
env.MY_SECRET - No environt variable is dumped to the console
- Clone repo
npm installnpm run build- Set environment variables using
SET,$env["..."],export ...or whatever your environment needs:- MY_SECRET="My little secret"
- ORIGIN=http://localhost:3000
- NODE_ENV=production (apparently telefunc needs this)
node buildto start the application- Open browser at http://localhost:3000
- Have a look at the rendered data and the server console
