Issue with Jest tests in Next.js
I seem to be hitting an error with Jest tests when using DrizzleORM in my tests.
I get
And then
6 Replies
The error is self explanatory, you can't use await outside an async function or top level in an ESM module. You need to a) use callback syntax, b) wrap all your code in an async function and call it at the end or c) use the callback
createConnection
if you driver provides it.Hey @angelelz, I'm not quite sure what you mean! I've just copied the client connection from the documentation
Which is what's throwing the error in a client.ts file.
Try including
in your package.json and run it with
DEV Community
Implicit ESM in Node.js with "type": "module"
A brief article on the usage of "type": "module" in package.json to have .js files parsed as ECMAScript Modules (ESM).
Hey @angelelz - Thanks for the help with this so far! I have tried the Module update, but it hasn't resolved it, as I'm trying to access the Client file through Jest, not directly to just run migrations (I'm wanting to generate some Integration tests across a few services we're overhauling from Prisma to Drizzle).
Any further help would be greatly appreciated
For anyone coming to this in the future, I've resolved this by doing:
Did you face any future problems or is it better to use
createPool
instead