sequelize.import上的错误:defineCall不是函数 [英] Error on sequelize.import: defineCall is not a function

查看:241
本文介绍了sequelize.import上的错误:defineCall不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到的错误是:

C:\Users\brend\project\server\node_modules\sequelize\lib\sequelize.js:392
      this.importCache[path] = defineCall(this, DataTypes);
                               ^
TypeError: defineCall is not a function
    at Sequelize.import (C:\Users\brend\project\server\node_modules\sequelize\lib\sequelize.js:392:32)
    at fs.readdirSync.filter.forEach (C:\Users\brend\project\server\src\models\index.js:20:35)

我正在学习关于节点,vue和一堆库的学习,但我一直无法弄清这一点.

I'm learning as I go with node, vue and a bunch of libraries, and I haven't been able to figure this out.

index.js如下:

index.js is as following:

const fs = require('fs')
const path = require('path')
const Sequelize = require('sequelize')
const config = require('../config/config')
const db = {}

const sequelize = new Sequelize(
  config.db.database,
  config.db.user,
  config.db.password,
  config.db.options
)

fs
  .readdirSync(__dirname)
  .filter((file) =>
    file !== 'index.js'
  )
  .forEach((file) => {
    const model = sequelize.import(path.join(__dirname), file)
    db[model.name] = model
  })

db.sequelize = sequelize
db.Sequelize = Sequelize

module.exports = db

这是我的User.js,这是我目前拥有的唯一模型:

And here is my User.js, which is the only model I have currently:

module.exports = (sequelize, DataTypes) =>
  sequelize.define('User', {
    email: {
      type: DataTypes.STRING,
      unique: true
    },
    password: DataTypes.STRING
  })

还有必要的话,我的文件夹结构:

And if necessary, my folder structure:

-src
--app.js
--routes.js

--config
----config.js

--controllers
----AuthenticationController.js

--models
----index.js
----User.js

还有一个问题,就是我的app.js sequelize.sync()中没有定义,至少这是我的IDE所指示的.

There's also the thing that in my app.js sequelize.sync() is not defined, at least that's what my IDE indicates.

推荐答案

我在github sequelize上找到了它github ,替换

I found this on github sequelize github, replace

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

使用

var model = require(path.join(__dirname, file))(sequelize, Sequelize.DataTypes);

它对我来说适用于sequelize 6.3.0

It works for me with sequelize 6.3.0

这篇关于sequelize.import上的错误:defineCall不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆