question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

can't read 'name' of undefine (model.name = model is undefined? )

See original GitHub issue

Hello 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:open
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

7reactions
banavasicommented, Dec 15, 2018
module.exports = (sequelize, DataTypes) => {
  const User = sequelize.define('User', {
    email: {
      type: DataTypes.STRING,
      unique: true
    },
    password: DataTypes.STRING
  });
  return User;
}

The above code helped me.

1reaction
cocomattcommented, Mar 12, 2019

The answer provided by shashankshandilyav helped me. I wasn’t returning User.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property 'name' of undefined after creating a model
You need to create an instance of the User , public form: User; constructor(){ this.form = new User(); }.
Read more >
Cannot Read Property of Undefined in JavaScript - Rollbar
TypeError: Cannot read property of undefined occurs when a property is read or a function is called on an undefined variable.
Read more >
Cannot read property 'modelName' of undefined
i AM GETTing this error in this challenge . i am not able to clear the test. var personSchema= new mongoose.Schema( { name:{...
Read more >
Uncaught TypeError: Cannot read property '1' of undefined
This error is because there is a property field in that model, on that form that doesn't have his generic value defined, probably...
Read more >
typeerror: cannot read properties of undefined (reading 'findall')
when you use the sequelize model you need to use the defined model class name, which is "user" instead of "User" in line...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found