Replies: 2 comments
-
You need to use a factory pattern. Change your db to something like: // pseudocode...
let client;
const getConnection = () => {
if (client) return client;
const connection = await mysql.createConnection({ ... });
const db = drizzle(connection, { ... });
client = db;
return client;
} The intention is to defer the creation of the connection and the db instance, until you actually do need it, and once that's done, keep a reference to that instance, and serve the same instance on further calls to |
Beta Was this translation helpful? Give feedback.
-
so am having similar problem using Nextjs latest (15). For example my Page.tsx is making a db call on render which is using the factory. next build actually invoke this during build time. same for next-auth setup when using a db adapter. It invokes the factory at build time. The issue for me is not having access to the env variable at build time. Thats next build, if you use trubo repo and set the "env" config in the build phase that works. I am not sure just solving the ability to provide env at build is a good solution, somehow the default build should not invoke to to db connection at all. the way i got around this is using |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Hi,
I have a
./db/index.js
which initialize the database pool and export the client,then the database client is being imported in a server action
./app/actions.js
like this,and the server action is imported in a page component
The
npm run build
complaints the following error when there is no database server running,How can I create the build without the database connection?
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions