@@ -17,6 +17,7 @@ import { trace } from '@opentelemetry/api'
1717import { wrapTracer } from '@opentelemetry/api/experimental'
1818import glob from 'fast-glob'
1919import 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'
2021import { prerelease , satisfies , lt as semverLowerThan , lte as semverLowerThanOrEqual } from 'semver'
2122
2223import type { RunConfig } from '../../run/config.js'
@@ -131,6 +132,10 @@ export const copyNextServerCode = async (ctx: PluginContext): Promise<void> => {
131132 return
132133 }
133134
135+ if ( path === 'server/functions-config-manifest.json' ) {
136+ await verifyFunctionsConfigManifest ( join ( srcDir , path ) )
137+ }
138+ 134139 await cp ( srcPath , destPath , { recursive : true , force : true } )
135140 } ) ,
136141 )
@@ -376,6 +381,19 @@ const replaceMiddlewareManifest = async (sourcePath: string, destPath: string) =
376381 await writeFile ( destPath , newData )
377382}
378383
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+ 379397export const verifyHandlerDirStructure = async ( ctx : PluginContext ) => {
380398 const { nextConfig } = JSON . parse (
381399 await readFile ( join ( ctx . serverHandlerDir , RUN_CONFIG_FILE ) , 'utf-8' ) ,
0 commit comments