We Fixed Environment Variables

Поділитися
Вставка
  • Опубліковано 27 кві 2023
  • T3 ENV IS LIVE!
    GITHUB: github.com/t3-oss/t3-env
    SITE: env.t3.gg/
    HUGE shoutout to Julius for his hard work on this / jullerino
    ALL MY VIDEOS ARE POSTED EARLY ON PATREON / t3dotgg
    Everything else (Twitch, Twitter, Discord & my blog): t3.gg/links
    S/O Ph4seOne for the awesome edit 🙏
  • Наука та технологія

КОМЕНТАРІ • 89

  • @BSenta
    @BSenta Рік тому +18

    Thanks for giving a shout out to the engineer that actually built it

  • @0xtz_
    @0xtz_ Рік тому +52

    Man I was hoping to find this outside T3 😂

  • @andrewc8125
    @andrewc8125 Рік тому +2

    Such useful info! Thank you😊😊

  • @kiryls1207
    @kiryls1207 Рік тому +5

    6:04 the infamous dev pain

  • @souvlaki42
    @souvlaki42 Рік тому +8

    This package seems promising enough. I had similar issues with env files. I just used the cleanEnv function from the envalid package to fix them.

  • @CottidaeSEA
    @CottidaeSEA Рік тому +37

    I believe the issue with environment variables is generally that you don't know you need them until something breaks, then you need to find out what the values should be.
    It is simply pain, and if not documented properly you'll just cry yourself to sleep at night.

    • @inmosh
      @inmosh Рік тому +2

      In Django we have django-env package. With it you could setup variables so the project wont start until you set correct values

  • @rumisbadforyou9670
    @rumisbadforyou9670 Рік тому +79

    So you've reinvented config files again? Good job, it only took you 40 years 🥳

  • @cyberhighdiver
    @cyberhighdiver Рік тому +1

    How do you do quick cuts with ur short vids? Lossless cut seems to maybe do that

  • @pythagoran
    @pythagoran Рік тому +43

    I used to have to `export FOO=bar`
    But now I can add a new library, boilerplates, types, and build steps!
    Job security achieved.

  • @Leon-bb8fc
    @Leon-bb8fc Рік тому +12

    How is everyone OK with this... .env could be troublesome sometimes, but importing two new libs to just type check and pre-build validation???

    • @ricorico222
      @ricorico222 Рік тому

      Mabey on really medium to big projects this would really shine

  • @CommenterAccount
    @CommenterAccount Рік тому +1

    I frequently use env variables to tree shake in different envs at compile time. For example, any place you have process.env.NODE_ENV compiles to the actual value like "development", which tree shaking will interpret as a literal, which means "if ("development" === "production")" will tree shake out any code in this conditional. The approach in this package requires a runtime check which does not allow for tree shaking. Any thoughts on this tradeoff for this approach?
    A common example is for things like integrated devtools that I don't want shipped to production

  • @riser9644
    @riser9644 Рік тому +6

    Guys is this not over engineering

  • @FengHuang13
    @FengHuang13 Рік тому +2

    I've been using this for years 😂
    Does your package support merging of .env, .env.local, .env. and .env..local ?

  • @jii808
    @jii808 Рік тому

    Theo, any way to use enums (strings) instead of just string?

  • @SeanCassiere
    @SeanCassiere Рік тому +20

    Been ripping ct3a zod env stuff for awhile now, so it's great to have this.
    Also, how is the Next starting template sooo bad??? Like ct3a without ANY of the options feels waaay better than the Next default one.

  • @spotgaming4668
    @spotgaming4668 Рік тому +1

    That red swiggly line is one of the best creative thing, give a pat yourself on the back

    • @jim.....
      @jim..... Рік тому

      It'll be inspired by the typewind logo

  • @jepemz873
    @jepemz873 Рік тому

    Love it. SvelteKit also has something similar.

  • @adaliszk
    @adaliszk Рік тому +1

    I wonder if dotenv cannot be simirarly augmented. They already have checks and a loading mechanism, and it looks like zod could be used to check either the result or the initial environment variables.

    • @dddmasterduel4749
      @dddmasterduel4749 Рік тому +1

      Nestjs already does verify environment variables with a joi schema. Maybe, they could move it to dotenv somehow

  • @jvliwanag
    @jvliwanag Рік тому +5

    One thing i’ve been looking for is how to detect changes on the settings and have the system reactively adopt the new setting.
    For ex - new timeout setting just applies it the api client. But a database url change re-establishes a db connection pool to a new server.

  • @bj97301
    @bj97301 Рік тому

    How’s it work with eas and react native?

  • @agenordebriat
    @agenordebriat Рік тому +2

    And of course nexxel is already there with the Nuxt adapter/integration PR! 🥵

  • @johannes.schaffer
    @johannes.schaffer Рік тому

    What is the difference to just plain Zod?

  • @bhatvikrant
    @bhatvikrant Рік тому

    T3 OSS

  • @evry1lovesironman
    @evry1lovesironman Рік тому

    What's the extension at the bottom of the terminal?

  • @eraoul
    @eraoul 6 місяців тому

    I still don't really understand what "runtimeEnv" is used for, or why we have to copy/paste everything in there. More importantly, I wanted to verify that adding secret keys here doesn't pass them along to the client. Can someone confirm? This stuff doesn't seem to be documented anywhere; I only see mention of server: and client: bits but not "runtimeEnv".
    Edit: I tested for myself to verify accessing server env var on the client gives an error. But I still don't understand runtimeEnv. Also in create-t3-app we still have env.js instead of env.mjs -- not sure why that is.

  • @otockian
    @otockian Рік тому +5

    They suck ass in NextJs for sure, but work great in SvelteKit.

  • @ES-eb6pb
    @ES-eb6pb Рік тому +8

    bloatware...

  • @evilhex7245
    @evilhex7245 Рік тому

    What the difference between znv and t3-env? Libraries almost identical

  • @vranberry
    @vranberry Рік тому

    I've been trying to figure out why my .env.local file isn't working for days and you made me realize its because of not using 'export default' in next config. thank god you were lazy!

  • @dgcp354
    @dgcp354 Рік тому

    i use env-var but i will try this

  • @joseandkris
    @joseandkris Рік тому +1

    What is hard about env variables? I don't get it

    • @juraev0056
      @juraev0056 Рік тому +5

      nothing really, this is just nonsense

  • @riskitall7421
    @riskitall7421 Рік тому +2

    Over-engineering 💯

  • @mma93067
    @mma93067 Рік тому

    Or just use a toml file ??

  • @crowlsyong
    @crowlsyong Рік тому +1

    0:43 little things like giving credit where credit is due...it's super important. thanks for being a good dude.

  • @davidboeger6766
    @davidboeger6766 Рік тому +2

    I'm a systems guy, not a web dev, so maybe I'm out of touch, but were people not doing this kind of validation anyway? I've done several projects that have been configurable with environment variables, and I always did validation checks when starting the program. It seems strange to me that you would need a library to do this. I mean, maybe it could cut down on a bit of boilerplate, but don't you still have to specify the validation logic somehow? Also, I thought environment variables were conventionally optional. If you absolutely must provide them because they don't have default variables, they're usually better off as either program arguments or in a config file.

    • @prestonrasmussen1758
      @prestonrasmussen1758 Рік тому

      In my experience, env vars are generally put in a config file for deployments, and we use env vars for our local environments

    • @darylphuah
      @darylphuah Рік тому +1

      ​@@prestonrasmussen1758 config files should be for default values that don't change much per environment. Anything that has to change per environment (e.g. api endpoints, db server, etc) should be in the env file. The env file should also only be handled by your build tool and not checked into the code repository.

    • @prestonrasmussen1758
      @prestonrasmussen1758 Рік тому

      @@darylphuah I understand what you’re saying and assuming you’re a newer engineer.
      I’m not talking about a config file in the main repo. I’m talking about config files that end up populating the .env file upon deployment, along with secrets in your secret manager.
      At my current company we use GCP so we are using a config.yaml file along with the GCP secret manager for secret values to populate the env vars using k8s during deployment

    • @darylphuah
      @darylphuah Рік тому +1

      ​@@prestonrasmussen1758 i'm far from being new, but perhaps try to re-read your original comment from the perspective of someone who is new. It would easily be misunderstood.. then you'll be seeing things like "config_production.yml, config_staging.yml, config_dev.yml" files in the code repo together with its credentials.
      These are unfortunately things I've actually seen in codebases.

    • @whkqpbttpl
      @whkqpbttpl 5 місяців тому

      I agree, env vars should be validated as early as possible and throw an error if they don't exist. Then the server won't even start up or a build will fail if they are missing.
      It is funny how overcomplicated this has become with .env, .env.local, .env. and .env..local, and process.env and people defaulting values instead of throwing errors when they are missing.
      IMO .env files should only really be used locally for convenience and everything should come off process.env at build or run time.
      If they are needed on the FE they should be replaced at build time or explicitly returned from the backend in a single place and put on the window object.

  • @joshuaborseth
    @joshuaborseth Рік тому

    This is a really awesome solution, my company uses infisical which is another really cool env variable solution. Would recommend!

  • @anush8
    @anush8 Рік тому +5

    Oh my god. Please, don't you ever get bothered by the boilerplate? Like micro-optimizing everything makes everything esoteric and that's just terrible.

  • @maskedvillainai
    @maskedvillainai 11 місяців тому

    This took just about as long as building an entire app so…

  • @p-townhero
    @p-townhero Рік тому +1

    Theo talk about Pulumi! I just went to a GDG meet where the spokesperson talked about it and how versatile it is with many different languages!

  • @kaleabmelkie
    @kaleabmelkie Рік тому +5

    Env vars are a mess in React. This just makes me really appreciate the SvelteKit way (fully typed, checked at build because they're just direct imports, server/public separation). I like how this library has validation tho.

  • @qoobes
    @qoobes Рік тому

    Audio is out of sync for me

  • @howuseehim
    @howuseehim Рік тому

    Team effort

  • @Lemmy4555
    @Lemmy4555 Рік тому +3

    It doesn't make sense to me, environment variables are controlled values set by the system owner, why should add complexity by validating them!

    • @davidboeger6766
      @davidboeger6766 Рік тому

      Well, the obvious answer is for security, since using arbitrary user input is asking for trouble. Also, your statement is a bit of an oversimplification. Environments can get manipulated in lots of ways. It's common for CI/CD tooling to use them to inject things like access tokens, so validation could effectively be a test to ensure those pipelines are working as intended.

    • @Lemmy4555
      @Lemmy4555 Рік тому +2

      ​@@davidboeger6766 I don't agree, there's no way you can "manipulate" env variables unless you had access to the server where the app is running or the Dashboard where your service is hosted, but if someone with bad intentions got that far you have a huge problem somewhere else.
      About validating the CI/CD pipelines work as intended, this is like saying we don't trust how GitHub or whatever service you want to use work. Therefore I don't see your point.

  • @michaelscofield2469
    @michaelscofield2469 Рік тому +2

    please make a new fullstack project with nextjs, somethings changed :(

  • @ts8960
    @ts8960 Рік тому +1

    "env vars are hard" well u just made them 10 times harder

  • @dogoku
    @dogoku Рік тому

    This is like the Pokémon evolution of dotenv

  • @wlockuz4467
    @wlockuz4467 Рік тому

    6:04 I too wanna die when I run into issues with .js .mjs .cjs .ts .jsx .tsx .mjsx .cjsx
    I don't even know if .mjsx or .cjsx are real extensions but I am sure we'll invent them as we go.

  • @UocLv
    @UocLv Рік тому +10

    Man, more crap to do basic stuff. Just stop. Less is more!

    • @themartdog
      @themartdog Рік тому +1

      I agree, over-engineering at its finest

  • @viktorshinkevich3169
    @viktorshinkevich3169 Рік тому

    *something on javascriptian*

  • @jalalle1995
    @jalalle1995 Рік тому +6

    I wish JS devs could stop fixing things

  • @SoulSovereignty
    @SoulSovereignty Рік тому +4

    My problem is environment variables that are not known until practically the moment the app is deployed. For example, an MS Azure "Marketplace Offering" might deploy a React SPA, and that SPA needs to have an Azure AD "app registration client id" for an OAuth flow it has implemented. Unfortunately, the "app registration client id" isn't known at build-time...only during deploy. So, in short, now my SPA app is deployed to an Azure App Service where the "app registration client id" is indeed within an environment variable...but the SPA app (being purely post-build static/bundled files) doesn't have access to that environment variable. FAIL.
    My current solution is to have the docker container (holding the SPA app) have a startup script which grabs the environment variable and then does a search-replace on the static SPA files before they are served. I wonder if anyone has a better approach.

    • @juliusmarminge
      @juliusmarminge Рік тому

      can you file an issue with a repro and your deployment steps? really curious to see if we can improve your situation.

    • @Fernando-ry5qt
      @Fernando-ry5qt Рік тому

      ugh that's rough..... I'll follow this comment in case something pops up haha

    • @SoulSovereignty
      @SoulSovereignty Рік тому

      @@juliusmarminge file an issue where? Give me an address (of a github repo?) and I'll post something.

    • @d.sherman8563
      @d.sherman8563 Рік тому

      You can use env variables at runtime without issue, they don’t have to be hardcoded.

    • @SoulSovereignty
      @SoulSovereignty Рік тому

      @@d.sherman8563 Nice!!! How??? Remember, a SPA is just a collection of static files; when serving static files there is no server-side rendering which can reference environment variables.

  • @maickolxd4611
    @maickolxd4611 Рік тому

    first?

  • @joelayoub2774
    @joelayoub2774 Рік тому

    Lollll

  • @alywa6099
    @alywa6099 Рік тому

    omg 7:27 💀

  • @jslbrt
    @jslbrt Рік тому +3

    Cool package. Embarrassing demo.

  • @elpolodiablo5486
    @elpolodiablo5486 11 місяців тому

    You can't call it a fix when there's no problem to begin with.

  • @MrKjelkenes
    @MrKjelkenes Рік тому +2

    Wrapper around zod parse(prosess.env) 🤷‍♂️ treeshake issue = next only

  • @tcortega
    @tcortega Рік тому +1

    Why would I use that if I can just add 4 more lines of code instead of importing an external framework to do something easy af? Please guys, just write "You're typing process.env wrong" by Matt.

  • @Thorax232
    @Thorax232 Рік тому

    zodSchema.parse(process.env)