Node.js 节点续集。打字错误

Node.js 节点续集。打字错误,node.js,sequelize.js,Node.js,Sequelize.js,这是我第一次尝试使用Sequelize,我正在尝试使用教程 我最初使用mysql,但我在更新mysql2时遇到了一个错误 我得到下面的错误 有人能看出我做错了什么吗 错误: node_modules/sequelize/lib/sequelize.js:380 this.importCache[path]=defineCall(this,DataTypes) TypeError:defineCall不是函数 part of package.json "dependencies": { "

这是我第一次尝试使用Sequelize,我正在尝试使用教程

我最初使用mysql,但我在更新mysql2时遇到了一个错误

我得到下面的错误

有人能看出我做错了什么吗

错误:

node_modules/sequelize/lib/sequelize.js:380

this.importCache[path]=defineCall(this,DataTypes)

TypeError:defineCall不是函数

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 with the 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;

models/
文件夹中除
index.js
之外的所有文件都是通过此行加载的

var model = sequelize.import(path.join(__dirname, file));
实际上,Sequelize单独加载每个模块,并调用每个模块导出的函数。Sequelize希望您导出一个模块,该模块包含两个参数:Sequelize对象和数据类型对象

function User(sequelize, DataTypes) {
  return sequelize.define('users', {
    // ...
  });
}

exports = module.exports = User;

如果“模型”文件夹中有与该格式不匹配的额外文件,则Sequelize将不知道如何处理这些文件。
models/
文件夹中还有哪些其他文件?

除了
index.js
之外,您的
models/
文件夹中的每个文件都是通过此行加载的

var model = sequelize.import(path.join(__dirname, file));
实际上,Sequelize单独加载每个模块,并调用每个模块导出的函数。Sequelize希望您导出一个模块,该模块包含两个参数:Sequelize对象和数据类型对象

function User(sequelize, DataTypes) {
  return sequelize.define('users', {
    // ...
  });
}

exports = module.exports = User;

如果“模型”文件夹中有与该格式不匹配的额外文件,则Sequelize将不知道如何处理这些文件。
models/
文件夹中还有哪些文件?

谢谢!!!为了指出这一点,我删除了一个散乱的文本文件,现在错误消失了。如果模型文件夹中需要更多文件,我需要做什么?你能给我举个例子吗?你可以在
index.js
中创建一个要忽略的文件数组,在
filter
调用中,你可以循环忽略文件,以确保在整个数组中找不到它。:)
const-ignored=['index.js','credentials.txt','sqlite.db']如果您使用Lodash,您可以执行类似
!\。包括(忽略,文件)
在你的
过滤器
呼叫中。嗯,我真的很难做到这一点。谢谢分享!!非常感谢。为了指出这一点,我删除了一个散乱的文本文件,现在错误消失了。如果模型文件夹中需要更多文件,我需要做什么?你能给我举个例子吗?你可以在
index.js
中创建一个要忽略的文件数组,在
filter
调用中,你可以循环忽略文件,以确保在整个数组中找不到它。:)
const-ignored=['index.js','credentials.txt','sqlite.db']如果您使用Lodash,您可以执行类似
!\。包括(忽略,文件)
在你的
过滤器
呼叫中。嗯,我真的很难做到这一点。谢谢分享!!