
Security News
Astral Launches pyx: A Python-Native Package Registry
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
@cloudflare/next-on-pages-next-dev
Advanced tools
> **Warning** > The submodule API needs to be finalized, in the meantime the submodule is being exported as `__experimental__next-dev`, the `__experimental__` prefix will be removed in a future release
Warning The submodule API needs to be finalized, in the meantime the submodule is being exported as
__experimental__next-dev
, the__experimental__
prefix will be removed in a future release
The next-dev
submodule of the @cloudflare/next-on-pages
package implements a utility that allows you to run the standard Next.js development server (with hot-code reloading, error reporting, HMR and everything it has to offer) with also adding local Cloudflare bindings simulations (implemented via Miniflare).
IMPORTANT: As mentioned above the module allows you to run the standard Next.js dev server as is and it only makes sure that Cloudflare bindings are accessible, it does not generate a worker nor faithfully represent the final application that will be deployed to Cloudflare Pages, so please use this only as a development tool and make sure to properly test your application with wrangler pages dev
before actually deploying it to.
The module is part of the @cloudflare/next-on-pages
package so it does not need installation, it exports the setupDevBindings
function which you need to import and call in your next.config.js
file to declare what bindings your application is using and need to be made available in the development server.
After having added the setupDevBindings
call to the next.config.js
you can simply run next dev
and inside your edge routes you will be able to access your bindings via process.env
in the exact same way as you would in your production code.
Let's see an example of how to use the utility, in a Next.js application built in TypeScript using the App router.
Firstly we need to update the next.config.js
file:
// file: next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {};
module.exports = nextConfig;
// we only need to use the utility during development so we can check NODE_ENV
// (note: this check is recommended but completely optional)
if (process.env.NODE_ENV === 'development') {
// we import the utility from the next-dev submodule
const { setupDevBindings } = require('@cloudflare/next-on-pages/next-dev');
// we call the utility with the bindings we want to have access to
setupDevBindings({
kvNamespaces: ['MY_KV_1', 'MY_KV_2'],
r2Buckets: ['MY_R2'],
durableObjects: {
MY_DO: {
scriptName: 'do-worker',
className: 'DurableObjectClass',
},
},
// ...
});
}
Next (optional but highly recommended) we create a TypeScript declaration file so that we can make sure that TypeScript is aware of the bindings added to process.env
:
// file: env.d.ts
declare global {
namespace NodeJS {
interface ProcessEnv {
[key: string]: string | undefined;
MY_KV_1: KVNamespace;
MY_KV_2: KVNamespace;
MY_R2: R2Bucket;
MY_DO: DurableObjectNamespace;
}
}
}
export {};
Note The binding types used in the above file come from
@cloudflare/workers-types
, in order to use them make sure that you've installed the package as a dev dependency and you've added it to yourtsconfig.js
file undercompilerOptions.types
.
Then we can simply use any of our bindings inside our next application, for example in the following API route:
export const runtime = 'edge';
export async function GET(request: NextRequest) {
const myKv = process.env.MY_KV;
const valueA = await myKv.get('key-a');
return new Response(`The value of key-a in MY_KV is: ${valueA}`);
}
When developing a next-on-pages application, this is the development workflow that we recommend:
next-dev
submodule.@cloudflare/next-on-pages
and preview it locally via wrangler pages dev .vercel/output/static
, this is the only way to locally make sure that every is working as you expect it to.FAQs
> **Warning** > The submodule API needs to be finalized, in the meantime the submodule is being exported as `__experimental__next-dev`, the `__experimental__` prefix will be removed in a future release
The npm package @cloudflare/next-on-pages-next-dev receives a total of 879 weekly downloads. As such, @cloudflare/next-on-pages-next-dev popularity was classified as not popular.
We found that @cloudflare/next-on-pages-next-dev demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 31 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.
Security News
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.