Next.js Discord

Discord Forum

Error in middleware using mysql2

Answered
Crucian carp posted this in #help-forum
Open in Discord
Crucian carpOP
I am using mysql2 to connect to my database and authenticate the user in my middleware.

It seems that mysql2 doesn't support the edge runtime, so I get this error: unhandledRejection: Error: The edge runtime does not support Node.js 'net' module.

How do I solve this?
Answered by Crucian carp
Thank you! I switched to serverless-mysql (https://www.npmjs.com/package/serverless-mysql). Do you know any other alternative packages?
View full answer

7 Replies

@Anay-208 Are you using it in the middleware
Crucian carpOP
Yes I am. I figured out, that I can't use mysql2 because of the edge runtime, but I need to connect to my mysql database to authenticate the session
@Anay-208 You can't use it in middleware. You can use alternate packages for it
Crucian carpOP
What would that be, for example? And does the approach of validating my session in the middleware make sense at all?
@Crucian carp What would that be, for example? And does the approach of validating my session in the middleware make sense at all?
Nextjs uses a edge environment in middleware, So it isn't supported. it does make sense to validate your session.
Crucian carpOP
Thank you! I switched to serverless-mysql (https://www.npmjs.com/package/serverless-mysql). Do you know any other alternative packages?
Answer