-
Notifications
You must be signed in to change notification settings - Fork 27.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime #58673
Comments
I got the same error in one of my files called "constants.ts":
And guess what't in that file. Just this: export const supportEmail = 'some@email.com'
export const announcementBarDisabledKey = 'announcementBarDisabled'
export const anonymousUniqueUserIdCookie = 'ajs_anonymous_id'
export const userIdCookie = 'userId'
export const publicChannels = ['ts-live-public-channel', 'ts-demo-channel'] Why would this give an error. It's nothing dynamic here 🤦 |
i'm used Next Auth v5. in
In my case, |
@joniel @IonelLupu i removed this piece of code
from |
@azr-arch I had to move the entire contents of my |
i see the same error ./node_modules/mongoose/dist/browser.umd.js Import trace for requested module:
but when i try to change edge runtime to nodejs runtime . please help me to solve this error. |
hey, you find any solution for this? |
yes, i use neon with drizzle |
Okay but i added the create user functionality in server action while submitting the form and everything goes fine. I already use mongoose and changing mongoose is not suitable for me |
I just don't get what's dynamic at this code: export const supportEmail = 'support@athotel.com'
export const announcementBarDisabledKey = 'announcementBarDisabled'
// Cookie names
export const anonymousUniqueUserIdCookie = 'ajs_anonymous_id'
export const userIdCookie = 'userId'
export const sessionIdCookie = 'sessionKey'
export const clerkAuthTypeKey = 'clerkAuthType' Or what's dynamic at this code: import dayjs from 'dayjs'
export function getValidDates(checkinInitial: string | null | undefined, checkoutInitial: string | null | undefined) {
// If the dates are invalid, set them to defaults
let checkin = dayjs(checkinInitial)
let checkout = dayjs(checkoutInitial)
if (
!checkinInitial ||
!checkoutInitial ||
!checkin.isValid() ||
!checkout.isValid() ||
checkin.isBefore(dayjs().subtract(1, 'day')) ||
checkout.isBefore(dayjs().subtract(1, 'day')) ||
checkout.isBefore(checkin)
) {
return {
// it seems that using MM-DD-YYYY (with dashes) as a format is Invalid Date in Safari
checkin: dayjs().add(30, 'day').format('MM/DD/YYYY'),
checkout: dayjs().add(32, 'day').format('MM/DD/YYYY'),
}
}
if (checkin.isSame(checkout)) {
checkout = checkout.add(1, 'day')
}
return { checkin: checkin.format('MM/DD/YYYY'), checkout: checkout.format('MM/DD/YYYY') }
} It's impossible to fix without just moving the entire |
Can you share your code or some reference on how you did that? Because I'm also using mongoose and moving it completely to another DB is simply not feasible for me. I tried creating an auth.js and auth.config.js to seprate the context but it is not working. |
Any solution on this? I am also using the latest version of next with mongoose. I am getting this error while trying to deploy to production..localhost is okay |
Okay mongoose doesn’t support edge runtime so if you doing any db thing in auth js it gives error with mongoose. To overcome this, move all these from auth js example : |
Can you share your source code |
yes sure |
I encounter the same issue, when I use Next.js 14.2.3 and Mongoose 8.3.4 to connect Mongodb Atlas. Creating an optimized production build ... ./models/user.ts The error was caused by importing 'mongoose/dist/browser.umd.js' in './models/user.ts'. Import trace for requested module:
Any solutions on this? If I just use Prisma to replace mongoose, is it an option? |
Depending on your use case. If you are fetching user in auth.ts then use prisma |
Thank you so much. I'm indeed fetching user in auth.ts, so I will try. By the way, I also tried to downgrade my Next.js to older version, but it didn't work. Because the Next-Auth 5@beta depends on the latest version of Next.js. |
Use prisma in auth.js, and mongoose remains in the other part of the code |
Using |
Same issue here Creating an optimized production build ... ./node_modules\mongoose\dist\browser.umd.js Import trace for requested module:
"Because the Edge runtime only uses standard Web APIs, many packages are not compatible with it, such as the mongodb driver package." 2 articles I saw about Authjs, Magic Links Email Provider with MongoDB as backend also mentioned and provided a workaround. I wish I could see a video with this workaround being practically utilized and built. |
Using prisma to replace the mongoose part in your auth.ts, this issue will be fixed. Go to read the documentation on the official website of Prisma, there are some examples for mongodb. |
Thank you. Anyways following Article and comparing from a previous app i build all i did was remove the middleware file (middleware.ts) and npm run build was then successful. |
My solution to a problem the same like this as stated in the response in here was as bellow: I add the following code in middleware.ts file export const config = {
unstable_allowDynamic: [
'/node_modules/sweetalert2/dist/sweetalert2.all.js',
],
}; so in your case the solution would be some thing like this: export const config = {
unstable_allowDynamic: [
'/node_modules/@babel/runtime/regenerator/index.js',
'/node_modules/next-auth/react/index.js',
],
//...rest of the config
}; |
This is the issue I am facing
Can someone please help here? |
Fixed my issue, |
Why does NextJS ever use |
I have auth.js file something like this. And getting the error
Please help to resolve this error |
Mongoose not support edge runtime so use prisma orm in auth.js file |
Thanks @traez , removing the middleware file worked like charm. |
finally, i came up with a solution, using mongoose (not any ORM like Prisma)and it didn't gives any error on build time and working perfectly in production. |
What ended up working? |
I resolved this issue in my Next.js project using the following configuration. I am using the latest version of Next.js: this is my config:
I successfully resolved the issue in my case. I hope this is helpful for you! |
I solved the issue by removing an import. Let's say that I have @/app/lib/db-connection.ts, if in @/app/lib I have an index.ts exporting the contents of db-connection.ts and I use some code of other file in the middleware by using import { myfunction } from @/app/lib, it will import that db-connection.ts file which has the connection with mongoose and will throw the error. So the solution in this case would be to remove the export * from "./db-connection" in @/app/lib/index.ts, then import { dbConn } from "@/app/lib/db-connection" where dbConn function is required. This problem happened when using auth.js v5 and middleware, same as some other people, so for them resolving this import "hell" should fix the problem. Additionally, server actions can't be call from middleware, or at least node runtime server actions, so if you need to perform some database check or something else you should put that code in a route handler and fetch it from middleware or some other non node runtime code, as auth code for auth.js v5. |
Easy solution: instead of server actions use api in auth.js or in middleware. |
Link to the code that reproduces this issue
https://github.com/azr-arch/realtime-chat-app
To Reproduce
try building the app with
npm run build
Current vs. Expected behavior
Current Behavior:
When I attempt to build my Next.js application for deployment, the build process fails. The error message indicates that dynamic code evaluation (e.g., 'eval', 'new Function', 'WebAssembly.compile') is not allowed in Edge Runtime. The error seems to originate from the
@babel/runtime/regenerator
andnext-auth/react
modules.Here's the error message I received:
Expected Behavior:
I expected the build process to complete without errors, allowing me to deploy my Next.js application.
Steps to Reproduce:
Verify canary release
Provide environment information
Which area(s) are affected? (Select all that apply)
Not sure
Additional context
also, any help regarding this
would be appreciated.
Note: this warning only shows during
npm run dev
The text was updated successfully, but these errors were encountered: