t3-oss / t3-env

https://env.t3.gg
MIT License
2.45k stars 79 forks source link

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

Open GRA0007 opened 1 month ago

GRA0007 commented 1 month ago

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:

https://github.com/t3-oss/t3-env/blob/5975abe1c91c04277565e06763bec2530eb44473/packages/core/src/index.ts#L276-L279