question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

es6 - Cannot read property '_parse' of undefined

See original GitHub issue

Hey all ! Thanks for the good work.

In my project, I am using zod@3.8.1 and for some technical limitations I need to manipulate z objects into an es6 codebase. More specifically the pick operator.

So I have my object definition in TS package (built to es6) :

export const Model = z.object({
  id: z.string().uuid(),
  name: z.string()
})

And in my es6 code I want to use a subset of this Model. Naively I do the following

import { Model } from '@mystuff/models'

const ModelSubset = Model.pick({
  name: true
})

The inferred type of ModelSubset looks right. But on the runtime, when I do this :

const myValidModel = ModelSubset.parse({
  name: 'Kikoo'
})

zod throws me :

TypeError: Cannot read property '_parse' of undefined

Redefining the object in the es6 package works though… 🤔

So, what am I missing ?

Thank you for reading and be well !

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

10reactions
LucasForstercommented, Jan 18, 2022

Hey!

zod throws me :

TypeError: Cannot read property '_parse' of undefined

I ran into the same error message and found this issue. Now while my problem is likely a different another one, I thought sharing this might still help others ending up here.

Essentially what I was doing is exporting a schema from one file, using it in another one to compose another schema, and then importing that composed schema back into the first file. While there isn’t a cyclic dependency per se, it causes the mentioned error at runtime.

See this CodeSandbox for an example: https://codesandbox.io/s/patient-butterfly-hsg3q?file=/src/index.ts The message isn’t as descriptive as in my local (larger) project, but removing this exact kind of import solved it for me. (Maybe this is generally “wrong” in terms of my tsconfig or simply unsupported by zod and I don’t know it, but I would intuitively expect it to work 🙈.)

0reactions
stale[bot]commented, Mar 19, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property 'parse' of undefined when requiring a ...
You get this error because in the file docuvieware-min.js , at the line 166 , the eval function isn't able to read the...
Read more >
Cannot Read Property of Undefined in JavaScript - Rollbar
TypeError : Cannot read property of undefined occurs when a property is read or a function is called on an undefined variable.
Read more >
How To Fix Cannot read Property '0' of Undefined in JS
To resolve your TypeError: Cannot read properties of undefined (reading '0') , go through these steps: Ensure you are using the correct ...
Read more >
Avoiding those dang cannot read property of undefined errors
Uncaught TypeError : Cannot read property 'foo' of undefined. ​ The dreaded error we all hit at some point in JavaScript development.
Read more >
[BUG] Cannot read property 'parse' of undefined (intl ... - GitHub
This seem to be a problem with the user code and not snowpack. From the description it would seem that you are calling...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found