Skip to content
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
7 changes: 7 additions & 0 deletions .changeset/modern-dancers-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@opennextjs/cloudflare": patch
---

fix: vercel og patch not moving to right node_modules directory

There are two separate places where the node_modules could be. One is a package-scoped node_modules which does not always exist - if it doesn't exist, the server functions-scoped node_modules is used.
1 change: 1 addition & 0 deletions examples/next-partial-prerendering/next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
typescript: { ignoreBuildErrors: true },
experimental: {
ppr: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ type TraceInfo = { version: number; files: string[] };
export function patchVercelOgLibrary(buildOpts: BuildOptions) {
const { appBuildOutputPath, outputDir } = buildOpts;

const packagePath = path.join(outputDir, "server-functions/default", getPackagePath(buildOpts));
const functionsPath = path.join(outputDir, "server-functions/default");
const packagePath = path.join(functionsPath, getPackagePath(buildOpts));

for (const traceInfoPath of globSync(path.join(appBuildOutputPath, ".next/server/**/*.nft.json"))) {
const traceInfo: TraceInfo = JSON.parse(readFileSync(traceInfoPath, { encoding: "utf8" }));
const tracedNodePath = traceInfo.files.find((p) => p.endsWith("@vercel/og/index.node.js"));

if (!tracedNodePath) continue;

const outputDir = path.join(packagePath, "node_modules/next/dist/compiled/@vercel/og");
const outputDir = getOutputDir({ functionsPath, packagePath });
const outputEdgePath = path.join(outputDir, "index.edge.js");

// Ensure the edge version is available in the OpenNext node_modules.
Expand Down Expand Up @@ -55,3 +56,14 @@ export function patchVercelOgLibrary(buildOpts: BuildOptions) {
writeFileSync(routeFilePath, node.commitEdits(edits));
}
}

function getOutputDir(opts: { functionsPath: string; packagePath: string }) {
const vercelOgNodeModulePath = "node_modules/next/dist/compiled/@vercel/og";

const packageOutputPath = path.join(opts.packagePath, vercelOgNodeModulePath);
if (existsSync(packageOutputPath)) {
return packageOutputPath;
}

return path.join(opts.functionsPath, vercelOgNodeModulePath);
}