Vercel Postgres 'missing_connection_string' localhost #2350
-
SummaryTrying out the new Postgres feature and I have created a simple test project with a Table in my Storage dashboard. Pulled the environment variables and running it locally with next dev. Running this insert import {sql} from "@vercel/postgres";
import {Post} from "@/interfaces/Post";
`export async function createPost(post: Post): Promise<void> {
try {
await sql`
INSERT INTO Posts (id, title, content, author, date)
VALUES (${post.id}, ${post.title}, ${post.content}, ${post.author}, ${post.date});
`;
} catch (e: any) {
console.log('Could not insert post into the database');
throw e;
}
}` Results in the following error:
the .env.local is setup correct and i can log these with correct results: console.log({
POSTGRES_URL: process.env.POSTGRES_URL,
POSTGRES_URL_NON_POOLING: process.env.POSTGRES_URL_NON_POOLING
}); ------EDIT--------- export async function fetchPosts() {
try {
const {rows, fields} = await sql`SELECT * FROM Posts;`;
return rows as Post[];
} catch (e: any){
console.log("Could not fetch posts from database");
return [];
}
} Additional informationNo response ExampleNo response |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 12 replies
-
Hi @denisgolubovic! This sounds similar to #2304. Do any of the suggestions in that discussion work for you? Another thing to try, if you have not already, is using If you still can't get it working, please share a minimal reproduction so we can look at the problem in more detail 🙏 |
Beta Was this translation helpful? Give feedback.
-
In case someone makes a small mistake that leads them into an hour long journey to end up here: My server action was connecting to Vercel Postgres. It was in a separate file. I forgot to put |
Beta Was this translation helpful? Give feedback.
-
Apparently just making it .env instead of .env.local works. |
Beta Was this translation helpful? Give feedback.
-
This error is thrown when using your database client side, and is difficult to find because the error is not that descriptive. It is often abstracted into other files, making it even harder to find! Some clues this may be your issue:
@amyegan Please could you share this with the storage team, I think we may need a better error message! I'm happy to provide a repro is necessary. Thanks everyone in this thread - you saved me lots of time! :) |
Beta Was this translation helpful? Give feedback.
-
For all vite users out there, you might want to check out the Vercel Documentation on this issue, pertaining to how vite does not expose environment variables not ending in |
Beta Was this translation helpful? Give feedback.
Hi @denisgolubovic! This sounds similar to #2304. Do any of the suggestions in that discussion work for you?
Another thing to try, if you have not already, is using
vercel dev
instead of other local dev commands likenpm dev
. If any of that gets it working for you, please let me know what worked and which framework you're using so I can share it with the Storage engineering team.If you still can't get it working, please share a minimal reproduction so we can look at the problem in more detail 🙏