Get started
Learn how to deploy full-stack (SSR) Next.js apps to Cloudflare Pages.
To create a new Next.js app, pre-configured to run on Cloudflare, run:
For more guidance on developing your app, refer to Bindings or the Next.js documentation ↗.
First, install @cloudflare/next-on-pages ↗:
Then, add a wrangler.toml
file to the root directory of your Next.js app:
This is where you configure your Pages project and define what resources it can access via bindings.
Next, update the content in your next.config.mjs
file.
These changes allows you to access bindings in local development.
Next.js has two “runtimes” ↗ — “Edge” and “Node.js”. When you run your Next.js app on Cloudflare, you can use available Node.js APIs — but you currently can only use Next.js’ “Edge” runtime.
This means that for each server-rendered route — ex: an API route or one that uses getServerSideProps
— you must configure it to use the “Edge” runtime:
Add the following to the scripts field of your package.json
file:
npm run pages:build
: Runsnext build
, and then transforms its output to be compatible with Cloudflare Pages.npm run preview
: Builds your app, and runs it locally in workerd ↗, the open-source Workers Runtime. (next dev
will only run your app in Node.js)npm run deploy
: Builds your app, and then deploys it to Cloudflare
Either deploy via the command line:
Or connect a Github or Gitlab repository, and Cloudflare will automatically build and deploy each pull request you merge to your production branch.
Optionally, you might want to add eslint-plugin-next-on-pages
, which lints your Next.js app to ensure it is configured correctly to run on Cloudflare Pages.
Once it is installed, add the following to .eslintrc.json
: