can't read 'name' of undefine (model.name = model is undefined? )
See original GitHub issueHello everyone. Can anyone help me? Getting this error sequelize doesn’t generate tabtracker.sqlite for me. ` db[model.name] = model ^
TypeError: Cannot read property ‘name’ of undefined at fs.readdirSync.filter.forEach (C:\Users\HyChhayrith\Documents\Code\github\webappWithFreecodecamp\server\src\models\index.js:16:18) at Array.forEach (<anonymous>) at Object.<anonymous> (C:\Users\HyChhayrith\Documents\Code\github\webappWithFreecodecamp\server\src\models\index.js:14:65) at Module._compile (module.js:652:30) at Object.Module._extensions…js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3) at Module.require (module.js:596:17) at require (internal/module.js:11:18) at Object.<anonymous> (C:\Users\HyChhayrith\Documents\Code\github\webappWithFreecodecamp\server\src\app.js:5:21) at Module._compile (module.js:652:30) at Object.Module._extensions…js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3) at Function.Module.runMain (module.js:693:10) at startup (bootstrap_node.js:191:16) at bootstrap_node.js:612:3 [nodemon] app crashed - waiting for file changes before starting…`
Below is my code `fs.readdirSync(__dirname).filter((file) => file !== ‘index.js’).forEach((file) => { const model = sequelize.import(path.join(__dirname, file)) db[model.name] = model })
db.sequelize = sequelize; db.Sequelize = Sequelize;`
Issue Analytics
- State:
- Created 5 years ago
- Comments:6
Top GitHub Comments
The above code helped me.
The answer provided by shashankshandilyav helped me. I wasn’t returning
User
.