Node.js   发布时间:2022-04-24  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了node.js – Sequelize对象不是函数大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在从这个 repo工作并尝试将其转换为POSTGResql这是我的错误

/home/otis/Developer/Shipwrecked/Hatchway/node_modules/sequelize/lib/sequelize.js:601
    this.importCache[path] = defineCall(this,DataTypes);
                             ^
TypeError: object is not a function
    at Sequelize.import (/home/otis/Developer/Shipwrecked/Hatchway/node_modules/sequelize/lib/sequelize.js:601:30)
    at db.sequelize (/home/otis/Developer/Shipwrecked/Hatchway/models/index.js:15:37)
    at Array.forEach (nativE)
    at Object.<anonymous> (/home/otis/Developer/Shipwrecked/Hatchway/models/index.js:14:6)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/otis/Developer/Shipwrecked/Hatchway/app.js:10:12)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/otis/Developer/Shipwrecked/Hatchway/bin/www:7:11)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)

以下是导致错误代码(models / index.js):

var fs        = require("fs");
var path      = require("path");
var Sequelize = require("sequelize");
var env       = process.env.NODE_ENV || "development";
var config    = require(__dirname + '/../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;

如果我注释掉以下行,则错误将停止:

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;
    });

Node.js错误不是我的强项,所以我不确定会发生什么,我还可以发布我的config.json,如果需要的话?

解决方法

如果我们看一下 code imports

if (!this.importCache[path]) {
    var defineCall = (arguments.length > 1 ? arguments[1] : require(path));
    this.importCache[path] = defineCall(this,DataTypes);
  }

…应该理解,它看起来像一个模型的文件夹有一个文件不是一个有效的模型文件和一般正确的模块.因此,试图通过“期望的”获取错误来激活它.检查文件夹模型.

大佬总结

以上是大佬教程为你收集整理的node.js – Sequelize对象不是函数全部内容,希望文章能够帮你解决node.js – Sequelize对象不是函数所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。