2

I have the general feeling that the middleware component of nextjs is not loading all resources into the runtime. I am using next.js v17.0.x . Apparently on middleware there is a differnt runtime called "edge" running, which seems not be capable to handle all resources.

Once I try to establish an connection to mongodb, middleware will throw this error:

error - (middleware)/node_modules/next-session/lib/compat.js (1:0) @ Array.ExpressStore error - The edge runtime does not support Node.js 'events' module.

My plan is to check a database session, if it exists, before continuing with the application logic, so basically on connection. In my opinion the middleware component should handle this, if no session is persisting it should redirect, or am I wrong?

marius
  • 1,118
  • 1
  • 18
  • 38
  • 1
    https://stackoverflow.com/questions/71106759/next-js-middleware-module-not-found-cant-resolve-fs – Daphoque Sep 12 '22 at 07:31
  • Next.js middleware does not support Node.js APIs. Why not use cookies and check against that, instead of checking the database every time? – juliomalves Sep 12 '22 at 21:18

1 Answers1

1

The edge runtime currently does not support mongoose. If you want to use it, refer to this article by mongoose.