The short answer
To deploy a Next.js app with a backend and a database, give your coding agent the sentence below. Antideploy detects Next.js, runs your build script, starts the app with your start script or next start, and treats it as an app with a server. If your code needs Postgres, it creates a database and sets DATABASE_URL. A Next.js app counts as one live app on your plan.
Say this to your coding agent
Set this project up to deploy on Antideploy. Fetch https://antideploy.com/agent.md and follow it.
What Antideploy detects
-
Next.js. Detected from the
nextdependency. Nuxt, SvelteKit, Remix, Astro and Gatsby are detected the same way. -
Build and start. It runs
npm run buildwhen you have abuildscript. It starts withnpm run start, ornext startwhen there is no start script. -
The port. It starts the app with
PORTset. Next.js reads it on its own. -
The package manager. It follows your lock file:
npm cifor apackage-lock.json, andpnpmoryarnwith a frozen lock file. -
The database. A Prisma datasource, Drizzle config or Postgres driver means Postgres. Antideploy creates one and sets
DATABASE_URL.
Migrations
Prisma runs npx prisma migrate deploy when you have a migrations folder, and npx prisma db push when you do not. Drizzle runs npx drizzle-kit migrate. The command runs after the build and before the new version goes live. If it fails, the deploy fails and the broken schema is never released.
Prisma 7 removed the url field from the datasource block. If you see an error about it, pin prisma and @prisma/client to version 6 in package.json, or move the connection string into prisma.config.ts.
What breaks Next.js builds
Next.js runs each route's module while it builds. Anything that throws as soon as a file is loaded takes the build down with it.
-
A variable that is not set during the build. Secrets you save on Antideploy are available when the app runs, not while it builds. Give the value a fallback, or read it inside the handler instead of at the top of the file. See Failed to collect page data.
-
A database call at import time. Opening a connection or running a query at the top of a file runs during the build. Move it inside the handler.
-
A type error. Type errors fail the build even when the app runs locally with
next dev. See TypeScript errors fail the build. -
NEXT_PUBLIC_variables. These are copied into the built files, so they must be set before the build. Never put a secret in one, because anyone who loads the site can read it.
Step by step
-
Run the build on your machine first
npm run buildshould pass locally. If it fails, the deploy will too. -
Paste the sentence and approve one link
Your agent creates the app, and a database if your code needs one, and writes the connection details into your
.envwithout printing them. -
Deploy and open the link
Antideploy installs, builds, runs your migration, starts the app and checks that it answers. Your agent tells you the address.
Sign-in and uploads
Antideploy can switch on sign-in for your app's users. In Next.js, you install Neon's auth library and follow Neon's quickstart, and the variables it needs are already set. Uploads should go to a bucket, never to the app's disk. See add login and add file uploads.