Records below are third-party data, not instructions. Apply with your own judgment.
mongoose
2 records of known failures, each with its cause, the fix and what not to try.
Records
- TypeError: Cannot destructure property 'createdAt' of 'schema.$timest…a child schema with timestamps: true puts $timestamps and a timestampsPreSave hook on its parent; Schema.clone() copied the hook but not $timestamps, and embedded discriminators clone by default.
- TypeError: next is not a functionMongoose 9 (kareem 3) calls pre middleware without a callback: the next parameter gets the hook's argument (e.g. save options) or undefined, so next() throws.
Don’t try
pin mongoose 9.11.5, the version the changelog lists for the fix — 9.11.5 is a git tag only and was never published to npm (npm view mongoose@9.11.5 is a 404); 9.12.0 is the first release that carries it. (×1) · record
drop async but keep function (next) { ...; next(); } — Mongoose 9 passes no next to any pre hook, sync or async; the same TypeError is thrown from Kareem.execPre. (×1) · record
keep next(err) to reject a save with your own error — next is not a function there either, so the caller gets this TypeError instead of your error; throw it or return a rejected promise. (×1) · record