File tree Expand file tree Collapse file tree 4 files changed +42
-9
lines changed
packages/cloudflare/src/cli/build Expand file tree Collapse file tree 4 files changed +42
-9
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @opennextjs/cloudflare " : patch
3+ ---
4+
5+ error early when a node middleware is detected
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import { compileInit } from "./open-next/compile-init.js";
1717import { compileSkewProtection } from "./open-next/compile-skew-protection.js" ;
1818import { compileDurableObjects } from "./open-next/compileDurableObjects.js" ;
1919import { createServerBundle } from "./open-next/createServerBundle.js" ;
20+ import { useNodeMiddleware } from "./utils/middleware.js" ;
2021import { getVersion } from "./utils/version.js" ;
2122
2223/**
@@ -58,6 +59,12 @@ export async function build(
5859 buildNextjsApp ( options ) ;
5960 }
6061
62+ // Make sure no Node.js middleware is used
63+ if ( useNodeMiddleware ( options ) ) {
64+ logger . error ( "Node.js middleware is not currently supported. Consider switching to Edge Middleware." ) ;
65+ process . exit ( 1 ) ;
66+ }
67+
6168 // Generate deployable bundle
6269 printHeader ( "Generating bundle" ) ;
6370
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import { createRequire } from "node:module";
22import path from "node:path" ;
33
44import { loadBuildId , loadPrerenderManifest } from "@opennextjs/aws/adapters/config/util.js" ;
5- import { type BuildOptions , esbuildSync , getPackagePath } from "@opennextjs/aws/build/helper.js" ;
5+ import { type BuildOptions , esbuildSync } from "@opennextjs/aws/build/helper.js" ;
66
77export function compileDurableObjects ( buildOpts : BuildOptions ) {
88 const _require = createRequire ( import . meta. url ) ;
@@ -12,16 +12,11 @@ export function compileDurableObjects(buildOpts: BuildOptions) {
1212 _require . resolve ( "@opennextjs/cloudflare/durable-objects/bucket-cache-purge" ) ,
1313 ] ;
1414
15- const baseManifestPath = path . join (
16- buildOpts . outputDir ,
17- "server-functions/default" ,
18- getPackagePath ( buildOpts ) ,
19- ".next"
20- ) ;
15+ const buildOutputDotNextDir = path . join ( buildOpts . appBuildOutputPath , ".next" ) ;
2116
22- const prerenderManifest = loadPrerenderManifest ( baseManifestPath ) ;
17+ const prerenderManifest = loadPrerenderManifest ( buildOutputDotNextDir ) ;
2318 const previewModeId = prerenderManifest . preview . previewModeId ;
24- const BUILD_ID = loadBuildId ( baseManifestPath ) ;
19+ const BUILD_ID = loadBuildId ( buildOutputDotNextDir ) ;
2520
2621 return esbuildSync (
2722 {
Original file line number Diff line number Diff line change 1+ import path from "node:path" ;
2+
3+ import { loadFunctionsConfigManifest , loadMiddlewareManifest } from "@opennextjs/aws/adapters/config/util.js" ;
4+ import * as buildHelper from "@opennextjs/aws/build/helper.js" ;
5+
6+ /**
7+ * Returns whether the project is using a Node.js middleware.
8+ *
9+ * @param options
10+ * @returns Whether the project is using a Node.js middleware
11+ */
12+ export function useNodeMiddleware ( options : buildHelper . BuildOptions ) : boolean {
13+ const buildOutputDotNextDir = path . join ( options . appBuildOutputPath , ".next" ) ;
14+
15+ // Look for the edge middleware
16+ const middlewareManifest = loadMiddlewareManifest ( buildOutputDotNextDir ) ;
17+ const edgeMiddleware = middlewareManifest . middleware [ "/" ] ;
18+ if ( edgeMiddleware ) {
19+ // The app uses an edge middleware
20+ return false ;
21+ }
22+
23+ // Look for the node middleware
24+ const functionsConfigManifest = loadFunctionsConfigManifest ( buildOutputDotNextDir ) ;
25+ return Boolean ( functionsConfigManifest ?. functions [ "/_middleware" ] ) ;
26+ }
You can’t perform that action at this time.
0 commit comments