Prepare Next.js for Deployment

Set Output Type

Set the output type in your next.config.js file:

  • export - For static site deployments.
  • standalone - For node server deployments. Standalone output type works for both VM and serverless deployments.

Sample Next.js config file

next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
  output: 'standalone',
};

export default nextConfig;

Force Dynamic Rendering

If your pages access server-side data, you can force dynamic rendering to ensure that the data is fetched at runtime. Databases deployed using Zonké are deployed in isolated subnets that are not accessible from build machines.

force-dynamic example

app/users/page.tsx
import { User } from '@prisma/client';
import prisma from '@/lib/prisma';

// Force the page to be rendered at runtime instead of at build time.
export const dynamic = 'force-dynamic';

const Users = async () => {
  // This line is what causes the failure in the build process. The database is in an isolated subnet, so a call to 
  // Prisma will fail because the build machine does not have permission to access the database. Your server will have
  // the necessary permissions to access the database.
  const users = await prisma.user.findMany();

  return (
    ...
  );
};

export default Users;