2 / 9
Aug 2024
1 month later

this code is not working on production mode. it’s showing error
The error was caused by importing 'mongoose/dist/browser.umd.js

14 days later

None of the mongoose examples with NextJS 14 are working on prod, just take your example and do “npm run build” , and you will get the same error that I am getting:
./lib/db.ts
Dynamic Code Evaluation (e. g. ‘eval’, ‘new Function’, ‘WebAssembly.compile’) not allowed in Edge Runtime
Learn More: Dynamic code evaluation is not available in Middleware | Next.js

The error was caused by importing ‘mongoose/dist/browser.umd.js’ in ‘./lib/db.ts’.
you can write me at: dvirben123@gmail.com , and I will give you access to my repo in order to see this error.

18 days later

Unfortunately, no.
But I found a good place to start the connection to mongo once the app is started, create a file: instrumentation.ts (root folder). and put the connection function there

Thak you for replying. Actually, I already did that but still it failed to build nextjs app on vercel. I am using “use server” everywhere almost. Integrated middleware.ts along with auth.js(v5). This is actual build error on my vercel deployment,

Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation The error was caused by importing 'mongoose/dist/browser.umd.js' in './lib/database/index.ts'.` If you know this issue, please let me know. I am unable to figure this out from past 30 days. Now, If i will not able to figure this out in next 2 days then I have decided to move to ReactJS over NextJS.

I think I found the issue on my side, I have replaced the server call with an API call in the auth.config.ts - authorize function (next-auth-v5 latest beta), and then “npm run build” passed and vercel deployment passed as well.