Deploy dev or preview to Vercel.
Love this new concept product and want to port current project wit h MongoDB and Prisma to it. Deploy to Vercel.
Test production deployment seems ok and we need to change package.json's build command to include npx convex deploy.
But we can not do it when we use dev or preview environment. Convex will link us to production URL. But if we remove convex deploy in command line, Vercel won't be even successfully compiled.
Check all over document, no clear answer.
Any good idea?
31 Replies
What happens when you run
npx convex dev
locally?Everything ok! So I could run dev locally perfectly. Just when I deploy to vercel for dev branch, error messages for convex/_generated/api appears. If I switch to production, and add npx convex deploy to build command, then it is ok. So the issue is here: I can not use npx convex deploy in dev branch in vercel, anything else I could do?
Why are you trying to deploy your dev environment? Previews would be the way to go for non-production deploys.
You mentioned previews aren't working, can you share the error(s) you're seeing when you try?
If I don's use convex deploy, the error message is...
Failed to compile.
./app/[lang]/(app.sno - public)/a/_components/app-navbar.tsx
Module not found: Can't resolve '@/convex/_generated/api'
https://nextjs.org/docs/messages/module-not-found
If I use it, the error message is
Running "pnpm dlx convex deploy --cmd 'pnpm build'"
Progress: resolved 1, reused 0, downloaded 0, added 0
Packages: +8
++++++++
Progress: resolved 29, reused 8, downloaded 0, added 8, done
Detected a non-production build environment and "CONVEX_DEPLOY_KEY" for a production Convex deployment.
This is probably unintentional.
Error: Command "pnpm dlx convex deploy --cmd 'pnpm build'" exited with 1
Error: Command "pnpm dlx convex deploy --cmd 'pnpm build'" exited with 1
You'll want to follow the previews guide for preview deployments - here's the one for Vercel if that's what your using: https://docs.convex.dev/production/hosting/vercel#preview-deployments
Using Convex with Vercel | Convex Developer Hub
Host your frontend on Vercel and your backend on Convex.
Are you checking in the
_generated
folder?Got it. So one more question, before I did any successful test for preview deploy. I need to commit the professional monthly plan first? Although monthly charge is average, still hope you guys could give dev a chance to test use before commitment. It is kind of not the best place to put road blocks for $$$ just saying. 😉
You could charge the preview deploy after the project is more than two or three.
No, you can use previews on the free plan!
Free plan is good for up to 5 projects and 2 developers.
I believe the only things you have to pay for at the moment are more projects/seats, certain integrations, performance upgrades, and enhanced support. Full comparison here: https://www.convex.dev/plans
I think @LarryHopeCode is right here, preview deploys are not available on the free plan. You can still use Vercel, Netlify etc. previews but you'd set them up to talk to the prod deployment.
We hope the instant reload of dev deployments (which run in the cloud, so you can also point preview deploys at the dev deployment!) is enough to get a sense of how Convex works — then once you start collaborating in a setting where you you need multiple different backends one each for multiple concurrent PRs that are changing your backend you can upgrade.
Interested in hearing about your flow where this is critical though — absolutely we want the free plan to be enough to provide an honest evaluation of Convex!
Ah! Sorry about the misinfo 🤦♂️
You can point your Vercel preview deployments at your dev deployment to evaluate it, or at prod - just be aware that the backend code may not be in sync with the frontend deploy
hi ian, do you know any guide on how to do this? im not sure what has to change for the vercel preview deployments to point at dev deployment or prod. i have my CONVEX_DEPLOY_KEY in vercel set to preview and production, but it didnt work for me. i think it's probably a wrong way to do it
Preview Deployments | Convex Developer Hub
Use Convex with your hosting provider's preview deployments
yea i have. i dont have a convex pro plan. are they the same set of instructions for pro plan vs free plan? or what is diff between them? i was also looking at https://docs.convex.dev/cli
From the first section of the doc:
Convex preview deployments require a Convex Professional Plan.
Ian you mentioned using your dev deployment in a Vercel preview, I think that’s what they’re trying to achieve.
I believe you just need to use the dev deploy key instead of a preview key to make that work, but that’s just off the top of my head.
oh got it. i think i misunderstood Tom's statement? "preview deploys are not available on the free plan. You can still use Vercel, Netlify etc. previews but you'd set them up to talk to the prod deployment."
i thought it means we can do the preview on a free plan, just setting it up to the prod deployment
So there’s Convex previews, which are convex deployments for specific git branches, and there are Netlify/Vercel previews, which are site hosting deployments. You can’t use Convex preview deployments on the free plan, but you can use Netlify/Vercel preview deployments if you use your dev or production deploy key.
Ah sorry for the confusion, re
"preview deploys are not available on the free plan. You can still use Vercel, Netlify etc. previews but you'd set them up to talk to the prod deployment.""talk to" was unclear. If you want to use Vercel/Netlify previews on a free plan I suggest using the Convex URL of your prod deployment. I do NOT suggest deploying your convex backend functions to prod! That would change behavior in prod every time you open a PR. But you can test out frontend changes using the production backend by not doing a Convex deploy in previews, just using the prod CONVEX_URL or NEXT_PUBLIC_CONVEX_URL or VITE_CONVEX_URL etc.
thanks all!
Wow. Still a big confusing after read all these. Our team is on Vercel Pro. And have three environment, main/preview/dev there 1:1 match with our Github. So right now, we could deploy main branch to Vercel with CONVEX_DEPLOY_KEY set. No problem. If we don't want to start the Convex pro plan 'yet', which deployment settings or environment we need to do?
For previews, don't set CONVEX_DEPLOY_KEY, and don't do a convex deploy as part of the build. Instead just set CONVEX_URL and build the frontend. That way it'll talk to your prod deployment, but not overwrite the functions. Note: it will have whatever version of the code is on production, so if you add new backend functionality it won't work yet. You can use the CONVEX_URL for your dev deployment (in .env.local) if you want to have the preview deploy talking to that one. In that case, if you deploy new code to the dev backend it might break the preview deploy. make sense?
This makes sense to me. Will vercel previews be smart enough to read the development or old production backend by setting CONVEX_URL?
@winsoroaks When you set CONVEX_URL in Vercel (say NEXT_PUBLIC_CONVEX_URL), it is used when your website is built. So in this case, your preview website is built with the URL of your production Convex backend. I hope that answers the question.
This is super old, but.. should we be? I didn't see this mentioned explicitly in a quick google search or a discord search.
I have been for a while, and am just resolving some conflicts while rebasing a branch, and it smelled like situations I've been in before where I was mistakenly checking something in that shouldn't be.
Yes, check it in
I don't believe it's documented anywhere, but it's been the consistent recommendation of the team in this Discord. And the only way I've ever done it personally.
I wonder where to add this to docs, but yeah check it in.
@panzacoder this way your code will typecheck + build even if you aren't running the
convex dev
command. This is especially useful if you want to run against existing backend just to edit CSS, but also for CI tasks like linting and typechecking.Hopefully the conflicts won't be as common now that it usually doesn't modify generated files on every version change
@ian I was rebasing a long running branch I hadn’t touched in a bit, so it did wind up just being the version changes that were in conflict. Thanks all!
I think the Best Practices page is likely a good fit, I actually stumbled across it searching for
convex _generated git tracking
or something like that, so some SEO is already potentially pointing thereBest Practices | Convex Developer Hub
Here's a collection of our recommendations on how best to use Convex to build