Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

delanobartolomei
seal-mask
.a{fill-rule:evenodd;}techdegree
delanobartolomei
Full Stack JavaScript Techdegree Student 14,052 Points

Sequelize TypeError: defineCall is not a function

Working on an express-generator project with Sequelize and SQLite.

I'm getting an Sequelize TypeError that I've been working on for hours but I'm coming up against a brick wall:

C:\-----\node_modules\sequelize\lib\sequelize.js:392 this.importCache[path] = defineCall(this, DataTypes); ^ TypeError: defineCall is not a function at Sequelize.import (C:\----\node_modules\sequelize\lib\sequelize.js:392:32) at C:\----\models\index.js:25:32

After doing some research, it appears that this could be caused when trying to import a non-sequelize object. Below is the problematic index.js file.

index.js start:

var Sequelize = require('sequelize');

var config = {
  dialect: 'sqlite',
  storage: 'library.db'
};

var connection = new Sequelize(config);
var contents = fs.readdirSync(__dirname);
var db = {};

I think the issue is in this snippet but I can't see it:

contents.forEach(function(file){
  var path = [__dirname, file].join('/');
  var model = connection.import(path);

  db[model.name] = model;
});

Object.keys(db).forEach(function(modelName){
  var model = db[modelName];

  if(model.associate) {
    model.associate(db);
  }
});


module.exports = {
  models: db,
  connection: connection
};

I do not have any function called defineCall, any idea where the error is coming from?