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

Remove process.env usage from the core #35

Merged
merged 2 commits into from
May 6, 2023

Conversation

chungweileong94
Copy link
Contributor

@chungweileong94 chungweileong94 commented Apr 30, 2023

If we try to use this package in Vite (SPA) project, it will throw an error Uncaught ReferenceError: process is not defined on client-side, as Vite is using import.meta.env instead of process.env.

So, the fix is to remove all the existing process.env usage.

Note that Astro is an exception, as most of the code are run/build in Node runtime, which the process.env is always available.

@vercel
Copy link

vercel bot commented Apr 30, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
t3-env ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 30, 2023 9:38am

@@ -100,11 +100,7 @@ export function createEnv<
): z.infer<ZodObject<TServer>> & z.infer<ZodObject<TClient>> {
const runtimeEnv = opts.runtimeEnvStrict ?? opts.runtimeEnv ?? process.env;

const skip =
opts.skipValidation ??
(!!process.env.SKIP_ENV_VALIDATION &&
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is originally from create-t3-app, and I don't think we should use this (process.env.SKIP_ENV_VALIDATION) anymore, and let the create-t3-app mention about this in docs instead.

@juliusmarminge
Copy link
Member

You just need to define the skipValidate option and this wont be hit. This is also stated in the docs.

Atleast thats how my tests have been concluded. Do you see other behavior?

@chungweileong94
Copy link
Contributor Author

@juliusmarminge Just notice that side note in the docs, but the explanation wasn't clear enough why the library reference process.env, even though the doc kinda mention about SKIP_ENV_VALIDATION a bit, but it shows as an example instead of mentioning that the library will use it internally.

@chungweileong94
Copy link
Contributor Author

IMO having to specify the skipValidation option in order to workaround the problem doesn't feel framework agnostic to me😕

Copy link
Member

@juliusmarminge juliusmarminge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine - I'll cave..

@juliusmarminge juliusmarminge added this pull request to the merge queue May 6, 2023
Merged via the queue into t3-oss:main with commit f0bc010 May 6, 2023
2 checks passed
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

Successfully merging this pull request may close these issues.

None yet

2 participants