Skip to content

automatically replace $env variables with process.env in edge functions #7556

Closed
@jdgamble555

Description

@jdgamble555

Describe the problem

Edge functions in Vercel do not work as expected. You have to specify the variable EXACTLY in process.env for it to work, while $env seem to get translated automatically in regular lambdas.

It would be nice if all $env variables were replaced with process.env so that I would not have to configure it manually with something like:

import { env } from '$env/dynamic/public';
import { createClient } from '@supabase/supabase-js';

const isLocal = Object.keys(env).length;

export const supabase = createClient(
    (isLocal ? env.PUBLIC_SUPABASE_URL : process.env.PUBLIC_SUPABASE_URL) as string,
    (isLocal ? env.PUBLIC_SUPABASE_ANON_KEY : process.env.PUBLIC_SUPABASE_ANON_KEY) as string
);

Describe the proposed solution

The vercel adapter does this if the edge: true is set.

Alternatives considered

My workaround code above.

Importance

would make my life easier

Additional Information

Obviously this would not be necessary if SvelteKit handled this internally, or if Vercel Edge functions handled env variables the same way as regular functions.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions