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

Server Side environment variables not working #35

Closed
timsawtellgo1 opened this issue May 23, 2023 · 7 comments
Closed

Server Side environment variables not working #35

timsawtellgo1 opened this issue May 23, 2023 · 7 comments

Comments

@timsawtellgo1
Copy link

timsawtellgo1 commented May 23, 2023

When following the instructions in the example app's README.md, the server side environment variables are undefined.

cd examples/with-app-router
yarn build
NEXT_PUBLIC_FOO=foo-value BAR=bar-value yarn start

and visiting http://localhost:3000/server-side I see

image

however visiting http://localhost:3000/client-side I see

image

I tried a few things, and the only way I could get the server side version to work was to set NODE_ENV=development when using yarn start.

after running NEXT_PUBLIC_FOO=foo-value BAR=bar-value NODE_ENV=development yarn start I see
image

This is not going to work in production because we need our NextJS app to run in production mode. It seems like the only way this library works as stated (identical server + client side environment variables) is if we run the app in development mode. Am I missing something?

Thanks heaps for this library by the way, gobsmacked when I learned of NextJS's approach to environment variables and this seems like a great way to solve it - I'm just unable to get server side env variables working in production mode though.

@loba-b
Copy link

loba-b commented Jun 30, 2023

Unfortunately, I have the same findings

@expatfile-bot
Copy link
Member

🎉 This issue has been resolved in version 1.7.0-alpha.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@HofmannZ
Copy link
Member

@timsawtellgo1 - Thanks for reporting this. We're currently working on a production-ready solution for using the app dir. The problem with the current example is that server components are statically generated by default at build time. To ensure the env vars are loaded, the server component needs to be forced to be dynamic.

I've updated the example. Can you give it a spin? :)

Additionally, I've added an issue for tracing the overall app router support. See: #69

@expatfile-bot
Copy link
Member

🎉 This issue has been resolved in version 1.7.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@HofmannZ
Copy link
Member

Hi 👋

(It's been a while, I know)

We've completely revamped our solution to support Server Components and the App Router. 🙌

Please check the development branch for docs and examples.

We've also published a version 2.0.0-alpha.1 on NPM. 🚀

@HofmannZ HofmannZ added enhancement New feature or request and removed released labels Oct 11, 2023
@expatfile-bot
Copy link
Member

🎉 This issue has been resolved in version 1.7.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@expatfile-bot
Copy link
Member

🎉 This issue has been resolved in version 1.7.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

No branches or pull requests

4 participants