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

Unsupported configuration for Nuxt - Vercel Edge

Open ZainW opened this issue 1 year ago • 3 comments

was converting my env usage from the built in nuxt one (using useRuntimeConfig) to the t3-env

ran into a a situation that is not supported

// serve/utils/kysely.ts
import { Kysely } from 'kysely'
import { PlanetScaleDialect } from 'kysely-planetscale'

import type { DB } from '~/lib/db'
import { env } from '~/env'

export const db = new Kysely<DB>({
  dialect: new PlanetScaleDialect({
    url: env.DATABASE_URL,
  }),
})

this is something that does work when using Nuxt's default runtime as such

import { Kysely } from 'kysely'
import { PlanetScaleDialect } from 'kysely-planetscale'

import type { DB } from '~/lib/db'

const config = useRuntimeConfig()
export const db = new Kysely<DB>({
  dialect: new PlanetScaleDialect({
    url: config.DATABASE_URL,
  }),
})

getting an error that crashes the edge function saying DATABASE_URL is required

this only happens when deploying to vercel-edge as opposed to just the vercel preset.

do environment variables load differently when bundled for edge? is there a way to make it use nuxt's own runtimeConfig https://nuxt.com/docs/api/composables/use-runtime-config#environment-variables

ZainW avatar May 06 '23 21:05 ZainW

do environment variables load differently when bundled for edge?

ah they might be treeshaking them from process.env on edge - similar to Next...

cc @nexxeln can you check plz :)

juliusmarminge avatar May 07 '23 11:05 juliusmarminge

yeah i can reproduce this

nexxeln avatar May 07 '23 12:05 nexxeln

Do we need to do manual destruction here too?

juliusmarminge avatar May 07 '23 12:05 juliusmarminge