Skip to content

Commit

Permalink
fix edge functions on Next 14.2.8 and newer by providing __NEXT_BUILD…
Browse files Browse the repository at this point in the history
…_ID (#877)
  • Loading branch information
Ambroos authored Sep 21, 2024
1 parent 73110d1 commit e890632
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/real-wolves-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@cloudflare/next-on-pages': patch
---

Provide \_\_NEXT_BUILD_ID env var to functions, making them compatible with Next v14.2.8 and newer.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Plugin } from 'esbuild';
import { build } from 'esbuild';
import { mkdir } from 'node:fs/promises';
import { mkdir, readFile } from 'node:fs/promises';
import { dirname, join, relative, resolve } from 'node:path';
import { normalizePath } from '../../utils';

Expand All @@ -25,6 +25,10 @@ export async function buildFile(
),
);

// Since Next 14.2.8 / https://github.com/vercel/next.js/pull/65426
// functions expect the build ID to be available as env var __NEXT_BUILD_ID.
const nextBuildID = await readFile(resolve('.next', 'BUILD_ID'), 'utf8');

await mkdir(dirname(filePath), { recursive: true });
await build({
stdin: { contents },
Expand All @@ -35,6 +39,9 @@ export async function buildFile(
external: ['node:*', `${relativeNopDistPath}/*`, '*.wasm', 'cloudflare:*'],
minify: true,
plugins: [builtInModulesPlugin],
define: {
'process.env.__NEXT_BUILD_ID': JSON.stringify(nextBuildID),
},
});
}

Expand Down

0 comments on commit e890632

Please sign in to comment.