Opt out env vars to be embedded at build time #49260
Replies: 3 comments 8 replies
-
let me know if this helps https://chat.elapse.ai/conversation/a133377b-0464-49a1-bbf6-1e00e7949f97 |
Beta Was this translation helpful? Give feedback.
-
I've run into this problem as well, and think a good solution would be if you could just provide a schema for your config where you can specify if an env var should be treated as "static" (bundled at build time) or "dynamic" (always read at boot time). Then the framework should just do the right thing. This would also decouple the concept of something being secret/public/sensitive with being static/bundled as it currently is using a prefix like Security also gets pretty dicey (as @icyJoseph showed above) as in these hybrid rendering setups as it can be hard to reason about where your code will run or what will get bundled. Again I think the solution there is specifying in a schema which items are sensitive, and then let the tooling do the right thing and protect you from making a mistake. After hacking together mediocre solutions so many times, I finally decided to build something more general that tries to solve all my config-related problems. I may be biased since I built it, but I really think it does. Here is a quick intro with some examples and screenshots. Internally the Next.js integration uses a webpack plugin to inject code replacements based on your schema, and additional code that prevents accidental leaks. Accessing a "dynamic" config item also calls next's Please give it a whirl and let me know what you think! |
Beta Was this translation helpful? Give feedback.
-
Can this please stop executing my code at build time? All of my checks for null env vars stop the build. And I most certainly do not want it embedding secrets in my docker container. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi.
I stumbled upon this issue. We do use a hosting system that accepts a docker image and then deploys it to multiple environments. Each environment has different set of environment variables, they can not be evaluated at build time.
So in order to prevent env var to be embedded at build time, we can use force-dynamic. But the issue is, that I use env var deep in the tree in some server components, but force-dynamic can be defined at route segment level only.
So I need to manually track if a page/layout directly or indirectly uses some server components that uses environment variable, and if so, I should add force-dynamic. That's not convenient to say the least.
Another point is that while env vars are not available at build time, they are available at runtime. And in my case they do remain static.
So I'd like to see a way to specify at what time an env var should be evaluated: at build time, at startup time or at every time it's accessed. Kinda similar to fetch's no-store and force-cache.
Similar but not the same issue: #48989
Beta Was this translation helpful? Give feedback.
All reactions