I am trying to get my database connection to run querys but it refuses and runs the error I provided in the title. I didn't change anything and even reverted back a few commits to see what happened but couldn't find the source of my issue. I created a db connection in my lib/db.ts file and tried to run a query in other server only files but nothing would run and it would throw the same error. I narrowed it down to the connection by making it run a query in the same lib/db.ts set up file to confirm everything was set up properly and it still threw the same error. I have never called a searchParams type, or whatever its saying, in my project. I am using AWS RDS to host my database and my url in the env variable is set up correctly after double checking it a 1000 times. I did make sure to run npm i to update my dependences and checked to make sure I had them installed. I have gone through every chatgpt step and nothing helped. I am at a complete loss.
lib/db.ts file
import 'server-only'
import { Pool } from 'pg'
declare global { var __pool: Pool | undefined }
const url = process.env.DATABASE_URL;
if (!url) {
throw new Error('Missing DATABASE_URL');
}
const pool = global.__pool ?? new Pool({
connectionString: url,
ssl: { rejectUnauthorized: false }
})
if(pool){
console.log(await pool.query('SELECT * FROM users'))
}
if (!global.__pool) global.__pool = pool
export default pool;
Any help is greatly appreciated.
Full stack trace:
⨯ TypeError: Cannot read properties of undefined (reading 'searchParams')
at eval (src/lib/db.ts:17:25)
15 |
16 | if(pool){
> 17 | console.log(await pool.query('SELECT * FROM users'))
| ^
18 | }
19 |
20 | if (!global.__pool) global.__pool = pool {
page: '/auth/login'
}
import 'server-only'is stands out to me. I have always just done'server-only 'without the import, and I have not seen any other code that uses theimportin the same line. If possible, try debugging with a breakpoint at line 17. Step into each line, until you seesearchParams, and then you can typically hover over it with your cursor to see the 'undefined' value. That my give you a bit more information on where the problem is and how it was causedimport 'server-only'is something ChatGPT added while trying to debug this, it said its used to prevent it from being accidentally imported to the client side so I kept it cause why not. About the breakpoint, I can't find anything regarding an issue or even a mention of searchParams. I am very confused by this. When the server starts, it establishes the pool and runs the health check (checking user table) in the same file but still throws the same error. I don't see anything new with the breakpoint.