Pages functions build error with Next.js

I have created a minimal Next.js app with TypeScript, and created a functions folder with the following API:

import { jsonResponse } from "../utils/jsonResponse";

export const onRequestGet: PagesFunction<{ FILES: KVNamespace }> = async ({ request, env }) => {
	return jsonResponse({
		time: new Date(),

The PagesFunction type is copied from example images app: at main · cloudflare/ · GitHub

jsonResponse utility function comes from the same example app.

When building on Cloudflare, and also verified locally with npx wrangler pages dev ./out, I get the following error:

Error: Transform failed with 1 error:
<stdin>:3:25: error: Expected ";" but found ":"
    at failureErrorWithLog (/Users/martinnormark/.npm/_npx/8c55f4bc76fffd7b/node_modules/esbuild/lib/main.js:1475:15)
    at /Users/martinnormark/.npm/_npx/8c55f4bc76fffd7b/node_modules/esbuild/lib/main.js:1264:29
    at /Users/martinnormark/.npm/_npx/8c55f4bc76fffd7b/node_modules/esbuild/lib/main.js:611:9
    at handleIncomingPacket (/Users/martinnormark/.npm/_npx/8c55f4bc76fffd7b/node_modules/esbuild/lib/main.js:708:9)
    at Socket.readFromStdout (/Users/martinnormark/.npm/_npx/8c55f4bc76fffd7b/node_modules/esbuild/lib/main.js:578:7)
    at Socket.emit (node:events:390:28)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at Socket.Readable.push (node:internal/streams/readable:228:10)
    at Pipe.onStreamRead (node:internal/stream_base_commons:199:23) {
  errors: [
      detail: undefined,
      location: {
        column: 25,
        file: '<stdin>',
        length: 1,
        line: 3,
        lineText: 'export const onRequestGet: PagesFunction<{ FILES: KVNamespace }> = async ({ request, env }) => {',
        namespace: '',
        suggestion: ''
      notes: [],
      pluginName: '',
      text: 'Expected ";" but found ":"'
  warnings: []

If I remove PagesFunction<> and the parameters (which I don’t use in this example) it works fine.

But this is just a minimal example, where I’m not using anything from the EventContext. I have APIs where I need to access KV namespaces via the env.FILES param.

Is there a known bug, or am I doing something wrong?

Then remove " PagesFunction<> ", according to you, it should work fine

I updated the question, to make it clear that this is a minimal example and I have APIs where I need the paramters :slight_smile:

I checked it, I believe that it is a bug, drop an email to [email protected]
Your query would be solved soon.

This seems to be related to the functions folder being tucked inside the Next.js app. I tried scaffolding a Vite app with React TS template and it works fine. Code for that here: GitHub - martinnormark/reactts-cf-pages-functions: Vite scaffolded React (TypeScript) app with Cloudflare Pages Functions