diff --git a/.changeset/modern-dancers-rescue.md b/.changeset/modern-dancers-rescue.md new file mode 100644 index 00000000..dde96c5e --- /dev/null +++ b/.changeset/modern-dancers-rescue.md @@ -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. diff --git a/examples/next-partial-prerendering/next.config.js b/examples/next-partial-prerendering/next.config.js index dec7014f..9249eb71 100755 --- a/examples/next-partial-prerendering/next.config.js +++ b/examples/next-partial-prerendering/next.config.js @@ -1,5 +1,6 @@ /** @type {import('next').NextConfig} */ const nextConfig = { + typescript: { ignoreBuildErrors: true }, experimental: { ppr: true, }, diff --git a/packages/cloudflare/src/cli/build/patches/ast/patch-vercel-og-library.ts b/packages/cloudflare/src/cli/build/patches/ast/patch-vercel-og-library.ts index 316bf6a8..00274138 100644 --- a/packages/cloudflare/src/cli/build/patches/ast/patch-vercel-og-library.ts +++ b/packages/cloudflare/src/cli/build/patches/ast/patch-vercel-og-library.ts @@ -18,7 +18,8 @@ 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" })); @@ -26,7 +27,7 @@ export function patchVercelOgLibrary(buildOpts: BuildOptions) { 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. @@ -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); +}