I have an odd issue with Next.js/mongoose I'd like some help troubleshooting. When I import a mongoose model into pages in my Next.js site to use in the getStaticProps function such as pages/index.js or pages/testimonies/index.js or pages/testimonies/[id].js it works fine. But, for some reason, now if I import said model (or another, different, model) into other sets of pages such as pages/vendors/index.js or pages/vendors[id].js or pages/whatever/whatever.js I get the following error (that is not received on any of the other pages and I've checked that the import path is in fact correct) :
TypeError: mongoose__WEBPACK_IMPORTED_MODULE_2___default().models is undefined
Could anybody help me troubleshoot what exactly is causing it to break suddenly? For example, here are two of the models in question (trimmed down to save space) which work fine in the pages mentioned but now seem to break everywhere else:
const testimonySchema = new mongoose.Schema({
//stuff
});
export default mongoose.models.Testimony || mongoose.model('Testimony', testimonySchema);
import mongoose from 'mongoose';
import bcrypt from 'bcryptjs';
const vendorSchema = new mongoose.Schema({
//stuff
});
//some model functions
export default mongoose.models.Vendor || mongoose.model('Vendor', vendorSchema);