@@ -17,6 +17,7 @@ import { trace } from '@opentelemetry/api'
17
17
import { wrapTracer } from '@opentelemetry/api/experimental'
18
18
import glob from 'fast-glob'
19
19
import type { MiddlewareManifest } from 'next/dist/build/webpack/plugins/middleware-plugin.js'
20
+ import type { FunctionsConfigManifest } from 'next-with-cache-handler-v2/dist/build/index.js'
20
21
import { prerelease , satisfies , lt as semverLowerThan , lte as semverLowerThanOrEqual } from 'semver'
21
22
22
23
import type { RunConfig } from '../../run/config.js'
@@ -131,6 +132,10 @@ export const copyNextServerCode = async (ctx: PluginContext): Promise<void> => {
131
132
return
132
133
}
133
134
135
+ if ( path === 'server/functions-config-manifest.json' ) {
136
+ await verifyFunctionsConfigManifest ( join ( srcDir , path ) )
137
+ }
138
+
134
139
await cp ( srcPath , destPath , { recursive : true , force : true } )
135
140
} ) ,
136
141
)
@@ -376,6 +381,19 @@ const replaceMiddlewareManifest = async (sourcePath: string, destPath: string) =
376
381
await writeFile ( destPath , newData )
377
382
}
378
383
384
+ const verifyFunctionsConfigManifest = async ( sourcePath : string ) => {
385
+ const data = await readFile ( sourcePath , 'utf8' )
386
+ const manifest = JSON . parse ( data ) as FunctionsConfigManifest
387
+
388
+ // https://github.com/vercel/next.js/blob/8367faedd61501025299e92d43a28393c7bb50e2/packages/next/src/build/index.ts#L2465
389
+ // Node.js Middleware has hardcoded /_middleware path
390
+ if ( manifest . functions [ '/_middleware' ] ) {
391
+ throw new Error (
392
+ 'Only Edge Runtime Middleware is supported. Node.js Middleware is not supported.' ,
393
+ )
394
+ }
395
+ }
396
+
379
397
export const verifyHandlerDirStructure = async ( ctx : PluginContext ) => {
380
398
const { nextConfig } = JSON . parse (
381
399
await readFile ( join ( ctx . serverHandlerDir , RUN_CONFIG_FILE ) , 'utf-8' ) ,
0 commit comments