francescov1 / mongoose-tsgen

A plug-n-play Typescript generator for Mongoose.
102 stars 24 forks source link

Error with type: schema.Types.Buffer and default: null #58

Closed Narretz closed 3 years ago

Narretz commented 3 years ago

This is a follow-up to https://github.com/francescov1/mongoose-tsgen/issues/47

I updated to 8.3.3 and got the same error as before TypeError: Cannot read property 'required' of null.

It seems like this happened because of the upgrade to mongoose 5.12.10.

Let me know if this way of defining a buffer is not supported anymore, or if this is a regression.

francescov1 commented 3 years ago

Hey @Narretz , thanks for submitting this. Could you provide an example of your schema and any config?

This is something that should be fixed and is even included in our tests now, see here.

Let me know how your setup differs from that example. Also may want to double check that your schema is defined properly and no old mongoose versions exist (delete node_modules folder and reinstall), old versions can sometimes be left behind and cause conflicts

Narretz commented 3 years ago

Hi @francescov1, here's a repro in a repo. https://github.com/Narretz/mongoose-tsgen-issues

Just run npm install && nprm run generate and mtgen should fail.

It looks like this is because in the package.json mongoose 5.12.9 is explicitly required, while mongoose-tsgen required mongoose ^5.12.10. (I assume that it loads the explictily required version instead of its own)

francescov1 commented 3 years ago

Fixed in 8.3.5! You're right, the package version conflicts cause issues. I moved mongoose to a peer dependency so it will use the users mongoose local installation now. Thanks for the example repo, super helpful 🚀