v4: use in nextjs middleware generates DynamicCodeEvaluationWarning · Issue #4113 · colinhacks/zod · GitHub
More Web Proxy on the site http://driver.im/
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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...
The text was updated successfully, but these errors were encountered:
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.
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.
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):zod/packages/core/src/util.ts
Line 310 in 46e96c7
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...
The text was updated successfully, but these errors were encountered: