The question is little unclear as bug itself is unclear in its way. The main question would be what are the possible cases which can lead to empty sequelize model loder.
user.js
const db = require('../db/models');
async testFunc function(data){
return new Promise((resolve, reject)=>{
try{
let user = await db.User.findOne({where:{id:data.id}});
resolve(user)
}catch(error){reject(error)}
})
}
module.exports={
testFunc
}
This is snippet of module defined which works fine on its own. But let's say if its used in another module the db is not loaded so throws error db.User is undefined
user.js
async testFunc function(data){
return new Promise((resolve, reject)=>{
const db = require('../db/models');
try{
let user = await db.User.findOne({where:{id:data.id}});
resolve(user)
}catch(error){reject(error)}
})
}
module.exports={
testFunc
}
Current workaround is require model loader inside each function(there are other similar functions too).
Just throwing the question to know possible mistakes and to find the better approach.