Technologies:
Tolerim
13 days ago
When running locally, the Vercel Postgres + Nuxt Starter template displays an error message stating that the connection string is missing.
As a web developer, I want to experiment with Vercel's new storage features, including Postgres, but I'm having an issue getting it to work. I used the Postgres-Nuxt template, which deployed without any issues. However, I'm unable to run it locally. So far, I've cloned the repository, run "npm i," and added a .env.local file with the variables provided by Vercel. When I run "npm run serve," I can see the static content, but not the database data. Instead, I get the error message "missingconnectionstring": You did not supply a 'connectionString' and no 'POSTGRESURL' env var was found." The get-users.ts file gets the data from the database. I've tried to fix the issue by adding the connectionString parameter to the createPool function, but it's giving me the error "invalidconnection_string": This connection string is meant to be used with a direct connection. Make sure to use a pooled connection string or try createClient() instead. I've consulted Vercel's error code documentation and quickstart guide, but they were of no help. Can someone assist me?
Answers(2)
Vogi
12 days ago
Verified Answer
I'm sorry to hear that you're having trouble running the Postgres-Nuxt template locally. According to the error message you're seeing, it seems like you haven't supplied a 'connectionString' and no 'POSTGRES_URL' env var was found. This error happens if you provided the wrong type of connection string to a connection method. For example, you passed a non-pooling postgres URL to the createPool method which expects a postgres URL that includes pooling.
You can try using the createClient() method instead of createPool() as suggested by the error message. Also, make sure that you have added the correct environment variables in your .env.local file. You can check if your environment variables are set correctly by running "echo $POSTGRES_URL" in your terminal.
If this doesn't work, you can try using an ORM like Kysely to access your Postgres database. Kysely is a type-safe and autocomplete-friendly TypeScript SQL query builder that can be used with Vercel Postgres.
I hope this helps! Let me know if you have any other questions.
Sources
Vercel Postgress Error Codes | Vercel DocsVercel Postgres + Nuxt Starter template gives 'missing_connection ...Using an ORM to access your Postgres database | Vercel DocsTolerim
13 days ago
It looks like you're having trouble connecting to your Postgres database when running the project locally. Based on the error message you provided, it seems like the connectionString property is missing.
In your get-users.ts file, you're using createPool() to create a new connection pool. However, you need to pass in the connection string as an argument in order to establish a connection.
Try updating your code to the following:
connectionString: process.env.POSTGRES_URL
});
Make sure to remove ?sslmode=require from your connection string as it's not necessary and may cause issues.
If this still doesn't work, try removing the createPool() function altogether and use createClient() instead, as suggested in the error message. Here's an example:
// ...
async function main() {
const client = new Client({
connectionString: process.env.POSTGRES_URL
});
try {
await client.connect();
const { rows: users } = await client.query('SELECT * FROM users');
return {
users
};
} finally {
await client.end();
}
}
export default defineEventHandler(async () => {
const startTime = Date.now();
const result = await main();
const duration = Date.now() - startTime;
return {
...result,
duration
};
});
Hope this helps!