8000 v4: use in nextjs middleware generates DynamicCodeEvaluationWarning · Issue #4113 · colinhacks/zod · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

v4: use in nextjs middleware generates DynamicCodeEvaluationWarning #4113

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

Open
McCulloughRT opened this issue Apr 12, 2025 · 4 comments
Open

Comments

@McCulloughRT
Copy link

Using v4 in nextjs middleware triggers the DynamicCodeEvaluationWarning

Top of the stack trace may be referencing this function, which does attempt new Function("") but catches its expected error (but not the warning):

new Function("");

Stack trace:
⚠ DynamicCodeEvaluationWarning: Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Edge Runtime Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation at eval (webpack-internal:///(middleware)/../../node_modules/@zod/core/dist/esm/util.js:175:9) at get value (webpack-internal:///(middleware)/../../node_modules/@zod/core/dist/esm/util.js:89:31) at eval (webpack-internal:///(middleware)/../../node_modules/@zod/core/dist/esm/schemas.js:836:74) at $ZodObjectLike.init (webpack-internal:///(middleware)/../../node_modules/@zod/core/dist/esm/core.js:26:13) at eval (webpack-internal:///(middleware)/../../node_modules/@zod/core/dist/esm/schemas.js:946:20) at $ZodObject.init (webpack-internal:///(middleware)/../../node_modules/@zod/core/dist/esm/core.js:26:13) at eval (webpack-internal:///(middleware)/../../node_modules/zod/dist/esm/schemas.js:719:55) at ZodObject.init (webpack-internal:///(middleware)/../../node_modules/@zod/core/dist/esm/core.js:26:13) at new ZodObject (webpack-internal:///(middleware)/../../node_modules/@zod/core/dist/esm/core.js:14:15) at Module.object (webpack-internal:///(middleware)/../../node_modules/zod/dist/esm/schemas.js:749:12) at eval (webpack-internal:///(middleware)/../../packages/db/src/schemas/ProjectDocument/Document/types.ts:18:61) ... REDACTED INTERNAL FILES...

I don't immediately have an idea how to get around triggering the warning, as I'm not sure how next generates it... testing for the runtime env variable before hitting that code is ugly but possible...

@McCulloughRT
Copy link
Author

This also generates an unrecoverable error on next build. Looks like zod currently cannot be imported to nextjs middleware (or other libraries that are imported to middleware) at all.

@raiyansarker
Copy link

Any updates on this?

@raiyansarker
Copy link

How come there is no updates on this?

@colinhacks
Copy link
Owner

I just merged a jitless flag that may alleviated this in some cases. #4368

But if Next is crashing during the build phase, there's little I can do. That'll require an upstream fix probably. That's not a very reasonable behavior on their part imo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
0