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

How to use this package with Remix? #144

Closed
piotrkulpinski opened this issue Nov 9, 2023 · 4 comments
Closed

How to use this package with Remix? #144

piotrkulpinski opened this issue Nov 9, 2023 · 4 comments

Comments

@piotrkulpinski
Copy link

Hi,
I've been using this package for some time now in NextJS and it works great.
I'd love to be able to use it in my Remix apps as well but I can't get it to work without some complicated workarounds like this.

Anyone successfully implemented this in Remix? Would love some advice.

Thanks

@chungweileong94
Copy link
Contributor

I've been away from Remix for quite some time now, but you should still be able to set it up on Remix using the core package

I will try to create an example when I free to do so, but you can refer to doc for now https://env.t3.gg/docs/core 🙂

@piotrkulpinski
Copy link
Author

piotrkulpinski commented Nov 10, 2023

I did follow the docs on this, but the thing with remix is that the components are loaded both from the server and the client, so every time I import the env.ts file in a component, I get the Uncaught ReferenceError: process is not defined error.

Any working example would be very helpful.
Thanks!

@chungweileong94
Copy link
Contributor

I did follow the docs on this, but the thing with remix is that the components are loaded both from the server and the client

So if the env variable is being use in both server and client, the env should be defined under client.

I get the Uncaught ReferenceError: process is not defined error

Unfortunately, I wasn't able to get the same error in my test, mind if you can create a repro?
Could it be something related to this issue? I also know that they recently release an early version of Vite support, which could also be a reason why it doesn't work as expected.

@piotrkulpinski
Copy link
Author

I don't want the env variable to be available in both server and client. I just wanted to share the same file for both types just like I did with NextJS.

I guess that's not going to work like this in Remix, so I've created 2 separate files as described in the docs: env.server.ts using process.env as runtimeEnv and env.client.ts using import.meta.env from Vite.

Looks like the issue is related to the new Vite integration in Remix as I'm currently using it (remix-run/remix#7934).

I'll close this now as the issues is clearly not related to this package.
Thank you for your help.

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

2 participants