HOW TO handle .env variables in VITE ?!

Поділитися
Вставка
  • Опубліковано 5 січ 2025

КОМЕНТАРІ • 21

  • @shmulimargulies5462
    @shmulimargulies5462 3 місяці тому +1

    Alem, have you considered showing us how to integrate and deploy with cloudflare?

    • @alemtuzlak
      @alemtuzlak  3 місяці тому

      To be honest ,not in the near future, I have many videos I want to do first

  • @rollotomasi1832
    @rollotomasi1832 4 місяці тому

    Another banger, thanks! 💥

  • @Ayydos
    @Ayydos 7 місяців тому

    thanks man, love the remix content

    • @alemtuzlak
      @alemtuzlak  7 місяців тому

      Thank you for watching 🙏🏻

  • @eleah2665
    @eleah2665 7 місяців тому

    Hello and thanks! Good to see you again.

    • @alemtuzlak
      @alemtuzlak  7 місяців тому

      Thank you! Was sick for a long time! 🤒 Good to be back

  • @shmulimargulies5462
    @shmulimargulies5462 7 місяців тому

    Another great one Alem!
    Would you consider doing future vids in 4K? Love your content 👍

    • @alemtuzlak
      @alemtuzlak  7 місяців тому +1

      I actually need to get around to explore if that's possible, my biggest issue is I use an ultra wide monitor instead of a 4k one so I'm not sure if that would work 😅

    • @shmulimargulies5462
      @shmulimargulies5462 7 місяців тому

      @@alemtuzlak Time to upgrade 😉

  • @planetmall2
    @planetmall2 7 місяців тому

    Great job!

  • @rollotomasi1832
    @rollotomasi1832 3 місяці тому

    Everything works beautifully, including the type coercion, however, VSCode is showing an error (red underline) on ProcessEnv:
    Property 'TEST' of type 'boolean' is not assignable to 'string' index type 'string | undefined'.ts(2411)
    I'll work on it. Thanks!

    • @alemtuzlak
      @alemtuzlak  3 місяці тому

      you probably need to make the validation schema cast it to a boolean, or you're not using the validated values from the zod validation but process.env.TEST directly?

  • @SajidAliSoftwareEngineer
    @SajidAliSoftwareEngineer 7 місяців тому

    Alem your content is very useful. One request can you please enlarge the text while recording the video.

    • @alemtuzlak
      @alemtuzlak  7 місяців тому +1

      Thank you so much, I'll make it even larger in the future!

  • @shmulimargulies5462
    @shmulimargulies5462 7 місяців тому

    Alem, I am getting an a typescript issue after following your guide and accessing my env directly:
    ```app/services/session.server.ts:9:15 - error TS2322: Type 'string | undefined' is not assignable to type 'string'.
    Type 'undefined' is not assignable to type 'string'.
    9 secrets: [process.env.SESSION_SECRET],
    ~~~~~~~~~~~~~~~~~~~~~~~~~~
    Found 1 error in app/services/session.server.ts:9```
    Specifically this crops up when I run `tsc - p cypress` (via a package.json script)
    Any idea how to fix this?

    • @alemtuzlak
      @alemtuzlak  7 місяців тому

      Have you tried using my getServerEnv helper? The reason you get this is because it's not validated by zod so it is indeed either a string or undefined

    • @shmulimargulies5462
      @shmulimargulies5462 7 місяців тому +1

      @@alemtuzlak I noticed that cypres declares its own global namespace, so I redefined the env there (by exporting the APP_ENV type) and it was happy

    • @alemtuzlak
      @alemtuzlak  7 місяців тому

      @@shmulimargulies5462 awesome!