Skip to content

Commit ad895ed

Browse files
authored
fix: vercel og patch not moving to right node_modules directory (#378)
* fix: vercel og patch not moving to right node_modules directory * move const * ignore ppr type errors
1 parent a07179c commit ad895ed

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

.changeset/modern-dancers-rescue.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@opennextjs/cloudflare": patch
3+
---
4+
5+
fix: vercel og patch not moving to right node_modules directory
6+
7+
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.

examples/next-partial-prerendering/next.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/** @type {import('next').NextConfig} */
22
const nextConfig = {
3+
typescript: { ignoreBuildErrors: true },
34
experimental: {
45
ppr: true,
56
},

packages/cloudflare/src/cli/build/patches/ast/patch-vercel-og-library.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@ type TraceInfo = { version: number; files: string[] };
1818
export function patchVercelOgLibrary(buildOpts: BuildOptions) {
1919
const { appBuildOutputPath, outputDir } = buildOpts;
2020

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

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

2728
if (!tracedNodePath) continue;
2829

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

3233
// Ensure the edge version is available in the OpenNext node_modules.
@@ -55,3 +56,14 @@ export function patchVercelOgLibrary(buildOpts: BuildOptions) {
5556
writeFileSync(routeFilePath, node.commitEdits(edits));
5657
}
5758
}
59+
60+
function getOutputDir(opts: { functionsPath: string; packagePath: string }) {
61+
const vercelOgNodeModulePath = "node_modules/next/dist/compiled/@vercel/og";
62+
63+
const packageOutputPath = path.join(opts.packagePath, vercelOgNodeModulePath);
64+
if (existsSync(packageOutputPath)) {
65+
return packageOutputPath;
66+
}
67+
68+
return path.join(opts.functionsPath, vercelOgNodeModulePath);
69+
}

0 commit comments

Comments
 (0)