I’m trying to connect next.js app to mongodb via mongoose in _middeware file(./pages/_middleware.ts )
But I get this error on incoming requests:
error – (middleware)node_modulesmongoosedistbrowser.umd.js (1242:0) @
ReferenceError: regeneratorRuntime is not defined
How can I fix it?
2
Answers
+1 I have the same issue when trying to use in the middleware the instance created for mongoose so I don’t have to connect it every time I make a request… but it seems this might not be supported yet.
It appears that it is not possible to use node api calls inside of NextJS middleware as this middleware is executed in the Edge runtime. Mongoose is a Node.js api, hence why is doesn’t work.
Edge and Node.js Runtimes