1.11.3 • Published 5 days ago

@cloudflare/next-on-pages v1.11.3

Weekly downloads
-
License
MIT
Repository
github
Last release
5 days ago

@cloudflare/next-on-pages

@cloudflare/next-on-pages is a CLI tool that you can use to build and develop Next.js applications so that they can run on the Cloudflare Pages platform (and integrate with Cloudflare's various other product offerings, such as KV, D1, R2, and Durable Objects).

This tool is a best-effort library implemented by the Cloudflare team and the community. As such, most, but not all, Next.js features are supported. See the Supported Versions and Features document for more details.

Quick Start

This section describes how to bundle and deploy a (new or existing) Next.js application to Cloudflare Pages, using @cloudflare/next-on-pages.

1. Select your Next.js app

To start using @cloudflare/next-on-pages, you must have a Next.js project that you wish to deploy. If you already have one, change to its directory. Otherwise, you can use the create-next-app command to start a new one.

npx create-next-app@latest my-next-app
cd my-next-app

We have confirmed support for the current version of Next.js at the time of writing, 13.4.2. Although we'll endeavor to keep support for newer versions, we cannot guarantee that we'll always be up-to-date with the latest version. If you experience any problems with @cloudflare/next-on-pages, you may wish to try pinning to 13.4.2 while we work on supporting any recent breaking changes.

2. Configure the application to use the Edge Runtime

For your application to run on Cloudflare Pages, it needs to opt in to use the Edge Runtime for routes containing server-side code (e.g. API Routes or pages that use getServerSideProps). To do this, export a runtime route segment config option from each file, specifying that it should use the Edge Runtime.

export const runtime = 'edge';

For more examples of this and for Next.js versions prior to v13.3.1, take a look at our examples document. Additionally, ensure that your application is not using any unsupported APIs or features.

3. Deploy your application to Cloudflare Pages

To deploy your application to Cloudflare Pages, you need to install the @cloudflare/next-on-pages package.

npm install -D @cloudflare/next-on-pages

Then you can deploy to Cloudflare Pages via the automatic Git integration. To do so, start by committing and pushing your application's code to a GitHub/GitLab repository.

Next, in the Cloudflare Dashboard, create a new Pages project:

  • Navigate to the project creation pages (Your account Home > Workers & Pages > Create application > Pages > Connect to Git).
  • Select the GitHub/GitLab repository you pushed your code to.
  • Choose a project name and your production branch.
  • Select Next.js as the Framework preset and provide the following options: | Option | Value | | ---------------------- | ---------------------------------- | | Build command | npx @cloudflare/next-on-pages@1 | | Build output directory | .vercel/output/static |
  • In the Environment variables (advanced) section, add a new variable named NODE_VERSION set to 16 or greater.
  • Click on Save and Deploy to start the deployment (this first deployment won't be fully functional as the next step is also necessary).
  • Go to the Pages project settings page (Settings > Functions > Compatibility Flags), add the nodejs_compat flag for both production and preview, and make sure that the Compatibility Date for both production and preview is set to at least 2022-11-30.

If you don't want to set up a Git repository, you can build your application (as indicated in Local Development) and publish it manually via the wrangler pages publish command instead (you'll still need to set the nodejs_compat flag for your project in the Cloudflare dashboard).

Note: When deploying via the Git integration, for better compatibility with tools such as yarn and pnpm we recommend using the Build system version 2 (that is the default so no action is required).

Local development

Standard Next.js development

You can develop your application locally by simply using the standard Next.js development server you'd normally use.

Warning: Please note however that the standard Next.js dev server does not work with a Cloudflare Pages compatible application/output, so it does not provide any reassurance that your application once built with @cloudflare/next-on-pages will actually correctly run, in order to make sure it does the only option (besides simply deploying it and hoping for the best) is to locally preview the application as described below.

Local preview

To preview locally your Cloudflare Pages application, simply run:

npx @cloudflare/next-on-pages

This command will build your Next.js application and produce a .vercel/output/static directory which you can then supply to Wrangler:

npx wrangler pages dev .vercel/output/static --compatibility-flag=nodejs_compat

Running npx @cloudflare/next-on-pages --help will display a useful help message which will detail the various additional options the CLI offers.

Cloudflare Platform Integration

Next.js applications built using @cloudflare/next-on-pages get access to resources and information only available or relevant on the Cloudflare platform, such are:

Such can be accessed by calling the getRequestContext function in server only code.

For example:

import { getRequestContext } from '@cloudflare/next-on-pages';

// ...

const { env, cf, ctx } = getRequestContext();

Warning: The function cannot be called in code from components using the Pages router.

Note: In order to make the function work in development mode (using the standard Next.js dev server) use the @cloudflare/next-on-pages/next-dev submodule.

TypeScript Env Type: the env object returned by getRequestContext implements the CloudflareEnv interface, add your binding types to such interface in order for get a correctly typed env object.

Note: getRequestContext throws an error if invoked when the request context is not available, if you prefer to receive undefined in such cases use getOptionalRequestContext instead, the latter is identical to getRequestContext except from the fact that it returns undefined when the context is not available.

Examples

To see some examples on how to use Next.js features with @cloudflare/next-on-pages, see the Examples document.

Troubleshooting

If you find yourself hitting some issues with @cloudflare/next-on-pages please check out our official troubleshooting documentation.

More Information

For more information on the project please check out the README in the next-on-pages github repository.

1.11.3

5 days ago

0.0.0-2d55e8f

5 days ago

0.0.0-fa02080

6 days ago

0.0.0-317e872

8 days ago

0.0.0-f150546

11 days ago

0.0.0-d1cafcc

11 days ago

1.11.2

14 days ago

0.0.0-1493f82

14 days ago

0.0.0-31c2627

14 days ago

1.11.1

21 days ago

0.0.0-f7bf30b

21 days ago

0.0.0-446e9af

22 days ago

0.0.0-c8a83f0

22 days ago

0.0.0-5170477

22 days ago

0.0.0-ad4ca02

1 month ago

0.0.0-a84add8

1 month ago

0.0.0-8da9da2

2 months ago

1.11.0

2 months ago

0.0.0-64988ca

2 months ago

0.0.0-53cb762

2 months ago

0.0.0-11308cf

2 months ago

0.0.0-8951ab0

2 months ago

0.0.0-c3fb67b

2 months ago

0.0.0-82aa1a4

2 months ago

0.0.0-f71ec2e

2 months ago

0.0.0-702f601

2 months ago

0.0.0-60eb0ae

2 months ago

0.0.0-9900517

2 months ago

0.0.0-555b4a7

2 months ago

1.10.0

2 months ago

0.0.0-46e53ec

2 months ago

0.0.0-b46977c

2 months ago

0.0.0-9b1d951

2 months ago

0.0.0-5187973

2 months ago

0.0.0-94543f0

3 months ago

0.0.0-739e2a7

3 months ago

0.0.0-90e140c

3 months ago

0.0.0-be1ab75

3 months ago

0.0.0-1cdde11

3 months ago

0.0.0-3846730

3 months ago

0.0.0-84e661d

3 months ago

0.0.0-687a39c

3 months ago

1.9.0

3 months ago

0.0.0-5712c57

3 months ago

0.0.0-06de52e

3 months ago

0.0.0-9f31f4f

3 months ago

0.0.0-f58ace8

3 months ago

1.8.6

3 months ago

0.0.0-0b1af18

3 months ago

0.0.0-1350eea

4 months ago

0.0.0-0a91001

4 months ago

0.0.0-519c6cc

4 months ago

0.0.0-3dd1f20

4 months ago

0.0.0-bb18e8a

4 months ago

0.0.0-05b6256

4 months ago

0.0.0-cc420a3

4 months ago

0.0.0-34af449

4 months ago

0.0.0-8e93067

4 months ago

0.0.0-30cf4fa

4 months ago

0.0.0-f07ea9b

4 months ago

0.0.0-1e516e3

4 months ago

0.0.0-2499cd7

4 months ago

1.8.5

4 months ago

1.8.4

4 months ago

0.0.0-ea73acc

4 months ago

0.0.0-f0df948

4 months ago

1.8.3

5 months ago

0.0.0-2b5c8f2

5 months ago

0.0.0-ed9a4ac

5 months ago

0.0.0-eb4d28c

5 months ago

0.0.0-352bf4b

5 months ago

0.0.0-72426c2

5 months ago

0.0.0-a4efc7b

5 months ago

0.0.0-37260e2

5 months ago

0.0.0-227f9cb

5 months ago

0.0.0-252c3ac

5 months ago

0.0.0-0c2c2fa

5 months ago

0.0.0-8fc1597

5 months ago

0.0.0-d0a2edd

5 months ago

1.8.2

5 months ago

0.0.0-20d0e0d

5 months ago

0.0.0-91acc21

5 months ago

0.0.0-8fe72f1

5 months ago

1.8.1

5 months ago

0.0.0-8ece962

5 months ago

0.0.0-f364224

6 months ago

0.0.0-dbe2c78

6 months ago

0.0.0-bc216b4

5 months ago

0.0.0-888ae85

6 months ago

0.0.0-d7b34cc

6 months ago

0.0.0-61d0a2f

6 months ago

1.8.0

6 months ago

0.0.0-733fed9

6 months ago

0.0.0-b7f9225

6 months ago

0.0.0-1e73555

6 months ago

0.0.0-b296765

7 months ago

1.6.3

8 months ago

1.6.2

8 months ago

1.6.1

8 months ago

1.6.0

9 months ago

0.0.0-6bf6480

11 months ago

0.0.0-c0ab05a

11 months ago

0.0.0-8346e05

11 months ago

0.0.0-705a95b

9 months ago

1.7.4

6 months ago

0.0.0-c6621c6

10 months ago

0.0.0-b5e8631

7 months ago

0.0.0-9faf701

10 months ago

0.0.0-ea970f7

7 months ago

0.0.0-f9b7ced

7 months ago

0.0.0-c788def

9 months ago

1.5.1

9 months ago

1.5.0

10 months ago

0.0.0-29d3041

7 months ago

0.0.0-c3df4e0

7 months ago

0.0.0-c9167ea

6 months ago

0.0.0-6c28128

10 months ago

0.0.0-cb32baf

9 months ago

0.0.0-c06b437

9 months ago

0.0.0-b4c4245

10 months ago

0.0.0-5dae9b2

7 months ago

0.0.0-1e25a97

8 months ago

0.0.0-551fa05

10 months ago

0.0.0-1133a7f

7 months ago

0.0.0-5b44784

7 months ago

0.0.0-ab83858

7 months ago

0.0.0-476d26a

10 months ago

1.4.0

10 months ago

0.0.0-2d5dde9

6 months ago

0.0.0-4570aa6

9 months ago

0.0.0-a6b9d0e

8 months ago

0.0.0-5bfbbe1

9 months ago

0.0.0-32426e1

9 months ago

0.0.0-9a51c79

7 months ago

0.0.0-6c34550

8 months ago

0.0.0-226d562

10 months ago

0.0.0-7da1fd8

9 months ago

0.0.0-dacf52d

10 months ago

0.0.0-5af0ca3

7 months ago

0.0.0-1588974

10 months ago

1.3.1

10 months ago

0.0.0-53ad429

10 months ago

1.3.0

10 months ago

0.0.0-bf57ec9

6 months ago

0.0.0-5b4a5b7

8 months ago

0.0.0-619beea

10 months ago

0.0.0-68dd9e9

11 months ago

0.0.0-f08f2b9

10 months ago

0.0.0-0424aab

10 months ago

0.0.0-628f6bb

8 months ago

0.0.0-cb7ab43

11 months ago

0.0.0-ffbae15

10 months ago

0.0.0-df9d256

10 months ago

1.2.0

11 months ago

0.0.0-ef63ae2

10 months ago

0.0.0-671ff82

10 months ago

0.0.0-9b290cb

7 months ago

0.0.0-d24e241

7 months ago

0.0.0-ee237f3

6 months ago

0.0.0-fe6ea04

9 months ago

0.0.0-3179e4f

7 months ago

0.0.0-291bfde

9 months ago

0.0.0-b585099

8 months ago

0.0.0-c83d125

6 months ago

0.0.0-69efaa5

7 months ago

0.0.0-0fb53a7

8 months ago

0.0.0-68d905e

11 months ago

0.0.0-5d42e57

10 months ago

0.0.0-82dacc5

9 months ago

0.0.0-1c746ea

6 months ago

0.0.0-e75cd34

7 months ago

0.0.0-168496

8 months ago

0.0.0-2772725

10 months ago

0.0.0-3a95489

11 months ago

0.0.0-23562ad

8 months ago

0.0.0-505be1e

10 months ago

0.0.0-4572873

6 months ago

0.0.0-3dc3ac4

6 months ago

0.0.0-ea98a8f

10 months ago

0.0.0-76a8bb4

10 months ago

0.0.0-48779e5

10 months ago

0.0.0-b474580

7 months ago

0.0.0-adf0713

11 months ago

0.0.0-b3a2ca4

9 months ago

0.0.0-11afe0a

10 months ago

0.0.0-9734795

10 months ago

0.0.0-77369b6

7 months ago

0.0.0-33c5ff8

7 months ago

0.0.0-a1091b1

7 months ago

0.0.0-cf5234a

10 months ago

0.0.0-9a98561

10 months ago

0.0.0-9d5db04

6 months ago

0.0.0-b630232

10 months ago

0.0.0-7f94fd2

9 months ago

0.0.0-3affd17

10 months ago

0.0.0-2423529

7 months ago

0.0.0-500edef

6 months ago

0.0.0-f764fff

9 months ago

0.0.0-48796ca

6 months ago

0.0.0-072af87

8 months ago

1.7.3

6 months ago

1.7.2

7 months ago

1.7.1

7 months ago

1.7.0

7 months ago

0.0.0-7a18efb

10 months ago

0.0.0-c21c995

11 months ago

0.0.0-b151505

11 months ago

0.0.0-9a66adc

11 months ago

0.0.0-eae9f6a

10 months ago

0.0.0-ee6b7dc

10 months ago

0.0.0-6600d2a

7 months ago

0.0.0-bdf37d0

7 months ago

0.0.0-dc529d7

10 months ago

0.0.0-f65227f

8 months ago

0.0.0-5aefce5

10 months ago

0.0.0-660ed5e

10 months ago

0.0.0-92c865b

10 months ago

0.0.0-f1f5a95

10 months ago

0.0.0-daa32fd

11 months ago

0.0.0-b97ad52

11 months ago

0.0.0-f879ffd

11 months ago

0.0.0-14a0e77

11 months ago

0.0.0-7deb9d8

11 months ago

0.0.0-7d0c0f8

11 months ago

0.0.0-016b8d3

11 months ago

0.0.0-cb62938

11 months ago

0.0.0-cad492b

11 months ago

0.0.0-2f9cf97

11 months ago

1.1.1

11 months ago

1.1.0

11 months ago

0.0.0-e48c4a0

11 months ago

0.0.0-81ebcb7

11 months ago

0.0.0-64b8579

11 months ago

0.0.0-d91b24b

11 months ago

0.0.0-1be5e72

11 months ago

0.0.0-6212bfd

11 months ago

0.0.0-6455355

11 months ago

0.0.0-783dc79

11 months ago

0.0.0-2f63de8

11 months ago

1.0.2

11 months ago

0.0.0-2c87481

11 months ago

1.0.3

11 months ago

0.0.0-2dceb75

11 months ago

0.0.0-63002ef

11 months ago

0.0.0-b1c3a33

11 months ago

0.0.0-a9b8c3c

11 months ago

0.0.0-1703ed6

11 months ago

0.0.0-1a7e0e4

11 months ago

0.0.0-d835933

11 months ago

0.0.0-cc6c114

11 months ago

0.0.0-b021650

11 months ago

0.0.0-fb818bf

11 months ago

0.0.0-e6cdfaa

11 months ago

0.0.0-1f930d3

11 months ago

0.0.0-3fa7019

11 months ago

0.0.0-95b1704

12 months ago

0.0.0-3e2dad8

1 year ago

0.0.0-fd51777

12 months ago

0.0.0-c0ecec3

12 months ago

0.0.0-f72a56f

12 months ago

0.0.0-6fcb58b

1 year ago

0.0.0-ff90dde

12 months ago

0.0.0-81bfcdb

12 months ago

0.0.0-4740c02

1 year ago

0.0.0-b16622c

12 months ago

0.0.0-bb23b60

1 year ago

0.0.0-1a68931

1 year ago

0.0.0-39cfa74

12 months ago

0.0.0-c70151d

1 year ago

0.0.0-8a46b36

1 year ago

0.0.0-86df485

1 year ago

0.10.2

12 months ago

0.0.0-d4440ba

12 months ago

0.0.0-336f3a7

1 year ago

0.0.0-c844242

12 months ago

0.0.0-4f43b9b

12 months ago

0.0.0-b33639f

1 year ago

1.0.1

12 months ago

1.0.0

12 months ago

0.0.0-87e183b

1 year ago

0.0.0-d81c2e3

1 year ago

0.0.0-f010420

12 months ago

0.0.0-29b7547

12 months ago

0.0.0-ea761b8

1 year ago

0.0.0-0d9e155

1 year ago

0.0.0-360d9f0

1 year ago

0.0.0-f1d76cd

1 year ago

0.0.0-b3ff89f

1 year ago

0.0.0-e4a3ee4

12 months ago

0.0.0-89924e0

1 year ago

0.0.0-97c8739

12 months ago

0.0.0-e053756

12 months ago

0.0.0-701f0c2

1 year ago

0.0.0-f687d25

12 months ago

0.0.0-7817ecd

1 year ago

0.0.0-3f05e81

12 months ago

0.0.0-3447a97

1 year ago

0.0.0-3277f72

12 months ago

0.0.0-e2d2046

1 year ago

0.0.0-752ae09

1 year ago

0.0.0-758f588

1 year ago

0.0.0-e3b92c3

1 year ago

0.0.0-9f5b83c

1 year ago

0.0.0-3387ac9

1 year ago

0.0.0-cf43f44

1 year ago

0.0.0-dc88b27

1 year ago

0.0.0-119b55e

1 year ago

0.0.0-91f766f

1 year ago

0.0.0-087d393

1 year ago

0.0.0-4258489

1 year ago

0.0.0-6bb5dea

1 year ago

0.0.0-4afad15

1 year ago

0.9.0

1 year ago

0.0.0-b07e3bc

1 year ago

0.0.0-3fe3a7d

1 year ago

0.0.0-15f7ff5

1 year ago

0.10.1

1 year ago

0.0.0-23aa2df

1 year ago

0.0.0-d7e62c7

1 year ago

0.0.0-bddbe04

1 year ago

0.0.0-4dfd789

1 year ago

0.0.0-60e375f

1 year ago

0.0.0-a680db6

1 year ago

0.10.0

1 year ago

0.0.0-84d9d5c

1 year ago

0.0.0-2a159ed

1 year ago

0.0.0-b8b0bde

1 year ago

0.0.0-dc74ffe

1 year ago

0.8.0

1 year ago

0.0.0-3fa5b0e

1 year ago

0.0.0-4d3f879

1 year ago

0.0.0-8d4aaae

1 year ago

0.0.0-bdbf909

1 year ago

0.0.0-b87c51e

1 year ago

0.0.0-70b2e80

1 year ago

0.0.0-057baa0

1 year ago

0.0.0-4296d3e

1 year ago

0.0.0-9834066

1 year ago

0.0.0-04da2c9

1 year ago

0.0.0-dcbbb9a

1 year ago

0.0.0-e0c53fe

1 year ago

0.0.0-2d72906

1 year ago

0.0.0-8b4f6d5

1 year ago

0.0.0-824944e

1 year ago

0.0.0-7266442

1 year ago

0.0.0-f6c1d34

1 year ago

0.0.0-cc91567

1 year ago

0.0.0-b1845fd

1 year ago

0.0.0-f25e836

1 year ago

0.5.0

1 year ago

0.4.1

1 year ago

0.4.0

1 year ago

0.7.0

1 year ago

0.6.0

1 year ago

0.4.2

1 year ago

0.3.0

1 year ago

0.2.0

1 year ago

0.1.0

2 years ago