⨯ Error: The Middleware "/middleware" must export a `middleware` or a `default` function at [project]/node_modules/next/dist/esm/build/templates/middleware.js { INNER_MIDDLEWARE_MODULE => "[project]/src/middleware.ts [middleware] (ecmascript)" } [middleware] (ecmascript) (.next/server/edge/chunks/_608f43._.js:11284:11) at <unknown> (.next/server/edge/chunks/edge-wrapper_8e4124.js:693:27) at runModuleExecutionHooks (.next/server/edge/chunks/edge-wrapper_8e4124.js:738:9) at instantiateModule (.next/server/edge/chunks/edge-wrapper_8e4124.js:691:9) at getOrInstantiateModuleFromParent (.next/server/edge/chunks/edge-wrapper_8e4124.js:624:12) at esmImport (.next/server/edge/chunks/edge-wrapper_8e4124.js:142:20) at <unknown> (.next/server/edge/chunks/_608f43._.js:11323:69)
Environment
Reproduction URL
https://github.com/MoscoviumAlchemist/nextjs-authjs-lazy-init-with-middleware/tree/lazy-init-middleware-bug
Describe the issue
⨯ Error: The Middleware "/middleware" must export a `middleware` or a `default` function at [project]/node_modules/next/dist/esm/build/templates/middleware.js { INNER_MIDDLEWARE_MODULE => "[project]/src/middleware.ts [middleware] (ecmascript)" } [middleware] (ecmascript) (.next/server/edge/chunks/_608f43._.js:11284:11) at <unknown> (.next/server/edge/chunks/edge-wrapper_8e4124.js:693:27) at runModuleExecutionHooks (.next/server/edge/chunks/edge-wrapper_8e4124.js:738:9) at instantiateModule (.next/server/edge/chunks/edge-wrapper_8e4124.js:691:9) at getOrInstantiateModuleFromParent (.next/server/edge/chunks/edge-wrapper_8e4124.js:624:12) at esmImport (.next/server/edge/chunks/edge-wrapper_8e4124.js:142:20) at <unknown> (.next/server/edge/chunks/_608f43._.js:11323:69)
How to reproduce
A) Clone the repository https://github.com/MoscoviumAlchemist/nextjs-authjs-lazy-init-with-middleware/tree/lazy-init-middleware-bug B) Add
.env
or.env.local
file with:C) Run the app by doing:
npm run dev
Downgrading to
5.0.0-beta.19
the middleware won't throw errors, but since5.0.0-beta.20
it throwsRemoving lazy init (by editing
auth.ts
to remove therequest
param) and the middleware also loads correctly.Expected behavior
Middleware should export as
nextjs
expects even whennext-auth
lazy init is enabled.