Skip to content

Shared variables from an extended config throw when used on the clientΒ #240

@GRA0007

Description

@GRA0007

Say I have a common env config, and one specific to a Next.js site in my monorepo:

const common = createEnv({
  shared: {
    NODE_ENV: z.enum(['development', 'production', 'test']).default('development'),
  },
  experimental__runtimeEnv: {
    NODE_ENV: process.env.NODE_ENV,
  },
})

const siteEnv = createEnv({
  extends: [common],
  // Assume other variables here...
})

If I now try and use that shared NODE_ENV variable from my siteEnv config like siteEnv.NODE_ENV on the client side, t3-env will throw the Attempted to access a server-side environment variable on the client error, as I assume the proxy used to detect this doesn't take into account configs in the extends option when checking shared.shape:

const isServerAccess = (prop: string) => {
if (!opts.clientPrefix) return true;
return !prop.startsWith(opts.clientPrefix) && !(prop in shared.shape);
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions