t3-env icon indicating copy to clipboard operation
t3-env copied to clipboard

Errors in Nuxt example

Open lttr opened this issue 2 years ago • 5 comments

I'm trying to make this library work for Nuxt 3 application, but encountering errors:

Reproduction 1 (process.env not defined)

  1. Clone this repository
  2. cd examples/nuxt
  3. pnpm install
  4. pnpm run build
  5. pnpm run preview
  6. Open browser at localhost:3000
  7. There is an error in the console: Uncaught ReferenceError: process is not defined

The process variable is used here: https://github.com/t3-oss/t3-env/blob/b68140ae970c2626d56ed85b10be24dc909f8cab/packages/nuxt/index.ts#L22C66

Reproduction 2 (Invalid environment variables with an empty error object)

  1. Clone this repository
  2. cd examples/nuxt
  3. pnpm install
  4. pnpm run dev
  5. Open browser at localhost:3000
  6. There is an error in the console: ❌ Invalid environment variables: Object { }

The error originates from here: https://github.com/t3-oss/t3-env/blob/b68140ae970c2626d56ed85b10be24dc909f8cab/packages/core/index.ts#L123

lttr avatar May 10 '23 11:05 lttr

1st problem about process: Might be because the code is accessing process on the client, which is in turn because the code (the t3-env Nuxt package) forgot to treat the server and the client differently. I know it is Nuxt but I just posted an issue describing how I approach Astro SSR, which is of course treating server and client code differently, at #60.

2nd problem about empty object: I think Nuxt is replacing process.env with undefined in development mode, which causes Zod to spit error in formErrors, not fieldErrors <- which is an empty object (my wild guess, but probably right).

Overall it comes down to the problem of accessing process.env on client-side. I'm in Next.js land, not Nuxt, so don't know how Nuxt names things, but that's the start.

intagaming avatar May 10 '23 16:05 intagaming

@nexxeln is the nuxt guy here

juliusmarminge avatar May 22 '23 17:05 juliusmarminge

+1 Encountered Reproduction 2 too

ThimoDEV avatar May 24 '23 10:05 ThimoDEV

browser show only:

Screenshot 2023-07-28 at 15 03 34

reslear avatar Jul 28 '23 13:07 reslear

so it turns out the nuxt version is not working, also I seem to have done something that would work but when using doppler run - nuxi dev HMR does not work :(

reslear avatar Oct 17 '23 14:10 reslear