Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Behavior Change when clientPrefix is empty #192

Closed
DanSnow opened this issue Feb 16, 2024 · 2 comments
Closed

Behavior Change when clientPrefix is empty #192

DanSnow opened this issue Feb 16, 2024 · 2 comments

Comments

@DanSnow
Copy link

DanSnow commented Feb 16, 2024

Issue Description

The behavior of the clientPrefix parameter in the @t3-oss/env-core library has changed, causing unexpected errors.

Example

import { createEnv } from '@t3-oss/env-core'
import { z } from 'zod'

const env = createEnv({
  isServer: false,
  clientPrefix: '',
  client: {
    FOO: z.string(),
  },
  runtimeEnvStrict: {
    FOO: 'FOO',
  },
})

console.log(env.FOO) // Throws error after upgrading to v0.9

In version 0.8, the provided code was functioning correctly. However, after upgrading to version 0.9, executing the same code results in the following error:

Attempted to access a server-side environment variable on the client
@DanSnow DanSnow changed the title Behavior Change in clientPrefix Parameter Behavior Change when clientPrefix is empty Feb 16, 2024
@juliusmarminge
Copy link
Member

This is intended. If you want a client var without prefix use shared variables

@julius-retzer
Copy link

I'm running into same issue and using shared doesn't work. I see that there is this code in source

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

So it means that if we have clientPrefix: '' it will never be accessible on client? I'm always getting the Attempted to access a server-side environment variable on the client if I put the variables in shared, isServerAccess always returns true, even on client

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants