Deploying Next.js w/ Drizzle on Vercel with Turborepo
I have a turborepo with Next.js using
drizzle-orm
as a shared package.
A bit of context - I'm using a monorepo with drizzle and share the tables, types and schemas across all my apps by having a shared packages/database
library - that my Next.js app is consuming.
One issue I've had is that in order to get drizzle-orm
working in my monorepo I've had to install it globally ie. in my root level package.json
.
My package.json
at the root level looks like this at the moment:
Note that all of the packages above are not in either my packages/database
or apps/next
dependencies.
My Next.js app consume my database
library like this in the apps/next
application's package.json
"database": "1.0.0"
12 Replies
I've had no error in local development. But when trying to deploy to Vercel I've had this error;
Our friend GPT4 told me that;
I've seen a related question here -> https://github.com/orgs/vercel/discussions/228
GitHub
Deploying a solution with pg gives error: Could not resolve "pg-nat...
Im using pg in a few endpoints. I get this error when I deploy a sveltekit app to vercel. Error taken from log. Am I supposed to do any further configuration?
GitHub
Add
pg
(Postgres) to server components external packages. by leer...While exploring using Drizzle with the App Router, I noticed they have a callout for needing to explicitly add pg to serverComponentsExternalPackages.
Adding pg here prevents manually needing to mo...
You can also try to use Postgres.js driver
Instead of pg
Should be just few lines of code to change a connection and drizzle() import
and remove pg and pg-native deps
Thank you @Andrew Sherman !
I got this step working, but I'm stuck at linting step with wrong types for
drizzle-orm
This is the error;
did you enable
skipLibCheck
in tsConfig?That was the missing link @Andrew Sherman thank you !
You're the best man I made it work finally
Next.js + serverless Lambdas + drizzle-orm in a Turborepo
@jeanhdev Can I ask if and how exactly you got this issue resolved? I couldn't get it to work
Hey Andrew, Could you maybe help me out here?
Hey @Eko sure
So I finally used the postgres driver for Node instead of pg. Then I had to ‘skipLibCheck’ and it worked like a charm.
Thanks got it working 🙂
I did not have to do the skipLibCheck tho
@jeanhdev hey can i ask how you're running migrations? I'm trying to run it in the new new
instrumentation.ts
file and i'm running into an issue where next.js can't find the db foldervery curious about this, I'm trying to get instrumentation.ts to work as well, but getting an error trying to deploy a simple script