Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define process.env.__NEXT_BUILD_ID in edge functions to be Next 14.2.8+ compatible #877

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading