TypeError: next is not a function in pre-save hook (Mongoose v6+)
Author: dhruv1086kCreated Dec 12, 2025Updated Jun 21, 2026
I was following this backend series in 2025 and encountered an issue in the User model related to Mongoose version updates.
The Error:
TypeError: next is not a function
Reason:
In Mongoose v6+, when using async middleware, Mongoose does not pass the next argument automatically. So this code from the tutorial:
userSchema.pre("save", async function (next) {
if (!this.isModified("password")) return next();
this.password = await bcrypt.hash(this.password, 10);
next();
});Leads to the error because next is undefined.
Fix for Mongoose v6+:
Remove the next argument and the next() calls:
userSchema.pre("save", async function () {
if (!this.isModified("password")) return;
this.password = await bcrypt.hash(this.password, 10);
});Source: hiteshchoudhary/chai-backend