#Deploy next.js app to vercel that uses mysql2
19 messages · Page 1 of 1 (latest)
🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord
🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize
✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)
If you need a better view of the errors
Deploy next.js app to vercel that uses mysql2
You can’t use mysql2 in the edge runtime. Use nodejs instead
Thank you for the answer! Can you explain me how do I do that?
you have at least one route using mysql2 that is run on the edge runtime. simply switch to the nodejs runtime instead.
Ok, but what do I have to change in my files I’m not understanding. Is it a config file?
Hmmmm. Are you importing the src/auth.ts file into middleware?
Outside middleware, the edge runtime is opt in, so you simply remove the opt in declaration. In middleware you cannot opt out of the edge runtime so you cannot run mysql2 there
The thing is, I’m using Next Auth V5
And it’s supposed to be like this no?
Next-auth cannot do anything about the database driver not being supported on the edge runtime unfortunately.
If you happen to use planetscale, you can use their serverless driver which is compatible with the edge runtime: https://github.com/planetscale/database-js.
If you don’t use planetscale, tough luck. You have to do one of these:
-
Find a way to use the planetscale driver for databases outside planetscale. Doesn’t look like that is possible.
-
Not use middleware at all, and implement the authentication redirection yourself in all routes.
-
Migrate to planetscale (they don’t have a free plan) or neon (they have a free plan, but postgresql not mysql) because they have drivers supporting the edge runtime. Other database providers work too as long as they have an edge compatible way to query their databases.
So the problem is that I’m using mysql2 I can convert the queries and the other stuff to another database provider, can you recommend me the databases providers that works the best and are free?
Edge compatible database drivers require certain things to be done in the server where the database is hosted. So no, you can’t simply take a driver supporting the edge runtime to connect to your own db and expect it to work. Your database has to be in a place with the necessary infrastructure. Neon is the only place I know of that has a free plan and supports this
But migrating databases is not easy. I would just select option 2 here. You are not supposed to query your database in middleware