You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
config?.connectionString would be undefined when called from @vercel/postgres/src/index.ts', as createPool() is called without any parameters, as seen below
exportconstsql=newProxy(// eslint-disable-next-line @typescript-eslint/no-empty-function -- [@vercel/style-guide@5 migration]()=>{},{get(_,prop){if(!pool){pool=createPool();}// keep an eye on this -- it'll fail on certain cases, like private property access, which can// require weird things like binding or calling with an explicit `this` arg.// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- [@vercel/style-guide@5 migration]constval=Reflect.get(pool,prop);if(typeofval==='function'){// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call -- [@vercel/style-guide@5 migration]returnval.bind(pool);}// eslint-disable-next-line @typescript-eslint/no-unsafe-return -- [@vercel/style-guide@5 migration]returnval;},apply(_,__,argumentsList){if(!pool){pool=createPool();}// @ts-expect-error - we're breaking all kinds of rules// eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- [@vercel/style-guide@5 migration]returnpool.sql(...argumentsList);},},)asunknownasVercelPool&(<OextendsQueryResultRow>(strings: TemplateStringsArray,
...values: Primitive[])=>Promise<QueryResult<O>>);exportconstdb=sql;
postgresConnectionString('pool') returns process.env.POSTGRES_URL;. However, in Vite, process.env cannot be used as it is not exposed. We are told to use import.meta.env.[ENV_NAME] instead, and the environment variable's name has to be prefixed with VITE_, as seen here. While we are theoretically able to expose to process.env through
in vite.config.ts, it doesn't seem to work as of now. What I've observed is that process.env.POSTGRES_URL is undefined when vercel/postgres accesses it, but after the initial paint, it becomes defined. I will have to find a workaround to this.
Tech Stack
This issue is encountered when using Vercel's vercel/postgres with drizzle-orm/vercel-postgres and Vite.
Edit: I realized that checking for import.meta.env.POSTGRES_URL won't even work because vite restricts environment variables to be named with the prefix of VITE_.
Hence, it would be good to allow us to directly pass the connection string into the connectionPool function directly.
The text was updated successfully, but these errors were encountered:
AJR07
changed the title
VercelPostgresError: VercelPostgresError - 'missing_connection_string' - also check import.meta.env.POSTGRES_URL
VercelPostgresError: VercelPostgresError - 'missing_connection_string' - parameter for connectionString
Jul 1, 2024
Issue
Currently, in
@vercel/postgres/src/create-pool.ts
, it checks for the connection string usingconfig?.connectionString
would be undefined when called from@vercel/postgres/src/index.ts
', ascreatePool()
is called without any parameters, as seen belowpostgresConnectionString('pool')
returnsprocess.env.POSTGRES_URL;
. However, in Vite,process.env
cannot be used as it is not exposed. We are told to useimport.meta.env.[ENV_NAME]
instead, and the environment variable's name has to be prefixed withVITE_
, as seen here. While we are theoretically able to expose toprocess.env
throughin
vite.config.ts
, it doesn't seem to work as of now. What I've observed is thatprocess.env.POSTGRES_URL
isundefined
whenvercel/postgres
accesses it, but after the initial paint, it becomes defined. I will have to find a workaround to this.Tech Stack
This issue is encountered when using Vercel's
vercel/postgres
withdrizzle-orm/vercel-postgres
andVite
.Reproduction of Issue
Solution
Edit: I realized that checking for
import.meta.env.POSTGRES_URL
won't even work because vite restricts environment variables to be named with the prefix ofVITE_
.Hence, it would be good to allow us to directly pass the connection string into the
connectionPool
function directly.The text was updated successfully, but these errors were encountered: