node.js - Node Sequelize. TypeError -


this first stab @ using sequelize , trying tutorial work.

i used mysql got error update mysql2 did.

i error below.

can see doing wrong?

error:

node_modules/sequelize/lib/sequelize.js:380

this.importcache[path] = definecall(this, datatypes);

typeerror: definecall not function

part of package.json "dependencies": {     "body-parser": "^1.17.2",     "dotenv": "^4.0.0",     "ejs": "^2.5.7",     "express": "^4.15.3",     "express-session": "^1.15.5",     "md5": "^2.2.1",     "multer": "^1.3.0",     "mysql": "^2.14.1",     "mysql2": "^1.4.1",     "node-datetime": "^2.0.0",     "nodemailer": "^4.0.1",     "passport": "^0.4.0",     "passport-local": "^1.0.0",     "password-hash": "^1.2.2",     "random-string": "^0.2.0",     "sequelize": "^4.5.0" }   app.js var models = require("./models"); models.sequelize.sync().then(function() {     console.log('nice! database looks fine') }).catch(function(err) {     console.log(err, "something went wrong database update!") });  /models/index.js "use strict";  var fs = require("fs"); var path = require("path"); var sequelize = require("sequelize"); var env = process.env.node_env || "development"; var config = require(path.join(__dirname, '..', 'config', 'config.json'))[env]; var sequelize = new sequelize(config.database, config.username, config.password, config); var db = {};   fs     .readdirsync(__dirname)     .filter(function(file) {         return (file.indexof(".") !== 0) && (file !== "index.js");     })     .foreach(function(file) {         var model = sequelize.import(path.join(__dirname, file));         db[model.name] = model;     });  object.keys(db).foreach(function(modelname) {     if ("associate" in db[modelname]) {         db[modelname].associate(db);     } });   db.sequelize = sequelize; db.sequelize = sequelize;  module.exports = db; 

every file inside of models/ folder except index.js loaded line.

var model = sequelize.import(path.join(__dirname, file)); 

what happens sequelize loads each module individually , calls function exported each. sequelize expects export module takes 2 arguments, sequelize object , object of data types.

function user(sequelize, datatypes) {   return sequelize.define('users', {     // ...   }); }  exports = module.exports = user; 

if have files in models folder not match format sequelize not know them. other files have in models/ folder?


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -