Skip to content
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

ESM module in Zod 2 beta causing runtime error #215

Closed
lukeramsden opened this issue Nov 6, 2020 · 5 comments
Closed

ESM module in Zod 2 beta causing runtime error #215

lukeramsden opened this issue Nov 6, 2020 · 5 comments

Comments

@lukeramsden
Copy link

With Zod 2.0.0-beta.20:

Screenshot

With Zod 1.11, no error.

Only seems to happen when using the object type

// no crash
z.string();
z.date();
// crashes
z.object({});
z.object({
  id: z.string(),
});
@alfonmga
Copy link

alfonmga commented Nov 7, 2020

It's crashing for me too. Zod works fine on local but when I deploy my Next.js app to production (Vercel) it crashes with the error message: TypeError: Prototype value can only be an object or null.

Affected versions: 2.0.0-beta.20 (latest), 2.0.0-beta.19 and 2.0.0-beta.18.

It works fine on 2.0.0-beta.17, so looking at the commits pushed after 2.0.0-beta.17 ESM modules changes could be the origin of the issue.

@o-alexandrov
Copy link
Contributor

o-alexandrov commented Nov 8, 2020

Issue is most probably unrelated to react native, but related to ESM introduction only #208.
zod worked fine on 2.0.0-beta.16, but tried to upgrade to .20 and saw an issue:

  • it builds & can be bundled, but throws in runtime:
Object prototype may only be an Object or null: undefined

@colinhacks
Copy link
Owner

I removed the ESM module in zod@2.0.0-beta.21. If you upgrade your builds should work again.

I've also reproduced this issue. Now that I'm aware of this I'll be able to guarantee ESM compatibility before trying to ship an ESM module again. It's not trivial to fix so it'll take some time. There are certain internal circular imports inside Zod's source code that work fine with CommonJS modules but not with ESM.

@colinhacks
Copy link
Owner

colinhacks commented Nov 10, 2020

Gonna re-open because the root problem here isn't solved :(

@colinhacks colinhacks reopened this Nov 10, 2020
@lukeramsden lukeramsden changed the title Zod 2 object crashing in React Native ESM module in Zod 2 beta causing runtime error Nov 10, 2020
@colinhacks
Copy link
Owner

@aabedraba @alfonmga Actually I suppose this particular issue is solved, I'm re-opening #175 instead.

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

4 participants