```
This is index.ts file to create connection but when i call db somewhere else than i get an error
Error: No database connection string was provided to neon(). Perhaps an environment variable has not been set?
But I have set my env file correctly. Even console log gives correct output5 Replies
multiple-amethyst•10mo ago
Hmm, this is odd, do you get the same error if you hardcode the string?
national-gold•10mo ago
Yes, when the database connection string is hardcoded, everything works smoothly. I found a solution by adding the following to my
next.config.ts
multiple-amethyst•10mo ago
you shouldn't need the dotenv package when using Next.js 🤔
national-gold•10mo ago
It seems this approach addresses the issue by making
DATABASE_URL
accessible during both build and runtime, resolving any environment variable loading conflicts.
Exactly, but I tried using the dotenv package as part of troubleshooting to resolve the issue.unwilling-turquoise•10mo ago
doesn't nextjs expect .env.local ?