使用SQLite数据库处理express项目。
我正在得到一个我已经工作了几个小时的Sequelize TypeError,但我遇到了一个难题:
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在做了一些研究之后,似乎这可能是在尝试导入非顺序化对象时导致的。下面是有问题的index.js文件。
index.js:
var Sequelize = require('sequelize');
var config = {
dialect: 'sqlite',
storage: 'library.db'
};
var connection = new Sequelize(config);
var contents = fs.readdirSync(__dirname);
var db = {};
contents = contents.filter(function(file){
var currFileName = __filename.split('/');
var checkOne = file.substr(file.length - 3, 3) === '.js';
var checkTwo = file !== currFileName[currFileName.length - 1];
return checkOne && checkTwo;
});
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
};我没有任何名为defineCall的函数,知道错误是从哪里来的吗?
发布于 2019-03-27 04:01:56
这确实是由于导入了一个不是Sequelize模型的文件造成的。在我的例子中,这是因为我的index.js正在拉入我的测试文件以及位于同一目录中的模型。尝试添加另一个检查,如checkOne,以排除所有以.test.js结尾的内容。
https://stackoverflow.com/questions/47860060
复制相似问题