score:101
the error is caused by using the sequelize import object. instead you should use node's built in commonjs require
function. so change this line in your models/index.js
:
const model = sequelize['import'](path.join(__dirname, file))
to:
const model = require(path.join(__dirname, file))(sequelize, sequelize.datatypes)
you can also just regenerate the models
directory and readd your models without the old index.js
if you find that easier:
mv models models.bak && sequelize init:models && mv models.bak/index.js models.bak/index.js.bak && mv models.bak/* models/ && rm models.bak
that one liner will fix your problem if you have sequelize-cli installed globally. if you don't you can use this one:
npm i --save-dev sequelize-cli && mv models models.bak && npx sequelize init:models && mv models.bak/index.js models.bak/index.js.bak && mv models.bak/* models/ && rm models.bak
you may also need to update your config folder. i use a javascript config to inject envs, so i had to add to change my const config = require(...
line to reflect that. if you used one of my one liners your old models/index.js
file is now at index.js.bak if you need to grab any custom stuff from it.
score:0
check if you have exported the model using old javascript syntax.
in my case, it was enough to change the code from:
export default (sequelize, datatypes) => {
...
}
to
module.exports = (sequelize, datatypes) => {
...
}
score:0
people who tell downgrading not worked: watch out for your index.js file!
for me downgrading to ^5.22.3 and changing
module.exports = (sequelize, datatypes) => {
sequelize.define('user', {
email: {
type: datatypes.string,
unique: true
},
password: {
type: datatypes.string
}
})
}
to
module.exports = (sequelize, datatypes) =>
sequelize.define('user', {
email: {
type: datatypes.string,
unique: true
},
password: datatypes.string
})
worked. that was the problem for me.
score:1
- check that you do not have files in models directory that are not exporting anything.
- check that your exports are functions with same parameters as the instance it is being called in the require statement.
in any case like mine, i had empty files in my models directory. require(...) is not a function simply because the index logic is iterating over and importing files that do not export anything from the models directory.
score:1
in my case i replaced this code
const model = require(path.join(__dirname, file))( sequelize, sequelize.datatypes );
with this :
const model = require(path.join(__dirname, file)).default(sequelize, sequelize.datatypes);
score:8
this might help someone else out there, in version 6.6.5
it's deprecated and you should replace it with sequelize.define
.
score:10
as of now i was able to fix the issue by downgrading the sequelize module version in your package.json to "sequelize": "^5.22.3",
. do let me know if it is also fixed on your side.
edit: any sequelize version under < 6.0.0
should work as normal
Source: stackoverflow.com
Related Query
- sequelize "findbyid" is not a function but apparently "findAll" is
- Sequelize query is giving TypeError: undefined is not a function
- Sequelize findAll is not a function
- sequelize .create is not a function error
- Sequelize object is not a function
- Sequelize TypeError: phone.setUser is not a Function
- Sequelize findOrCreate(...).spread is not a function
- Sequelize TypeError build.save is not a function
- self.$expandAttributes is not a function with Sequelize
- Sequelize + Express TypeError: User.find is not a function
- error on sequelize raw query: query is not a function
- TypeError: Modelname.findById is not a function with sequelize nodejs
- sequelize belongsToMany giving TypeError: undefined is not a function
- val.replace is not a function - Sequelize
- Method set/add is not a function sequelize node js
- sequelize ERROR: this.lib.createConnection is not a function when using node
- Sequelize model loader import doesn't work on top level import but only works on function import
- Syncing sequelize models: sequelize.import() is not a function (and is deprecated)
- setDataValue is not a function after calling sequelize findAll method
- Sequelize string is not a function error , why?
- TypeError: _stream.Readable.from is not a function in sequelize node js
- Sequelize Model.destory() is not a function
- Sequelize TypeError Associate is not a Function
- Sequelize "object" does not have increment function
- Sequelize v6.2.0: include.model.getTableName is not function
- s.replace is not a function while using sequelize
- Sequelize does not return a value within a function
- Sequelize TypeError: defineCall is not a function
- Message.Create is not a function sequelize cli
- nodejs Sequelize orm model.validation not a function
More Query from same tag
- How can "sequelize.import()" import models from another file?
- Association in Sequelize
- How to configure sequalize & node mysql to use new aws rds root cert rds-ca-2019
- Sequelize - Query with Many-to-Many relationship using where and limit
- Multiline replace using sed
- NodeJS+Sequelize+Jade; Using the hasMany collection on an object
- Sequelize, apply transaction to other nested transactions
- Sequelize find in JSON field
- Wait for queries with sequelize
- Why promise.all crash an error but not sending promises one by one?
- Sequelize findAll and Join table
- How to count a many to many relationships and apply where clause with ORM Sequelize
- sequelize posting NULL in database(MySql)
- Sequelize findAll with association and foreign key
- how to set mysql datetype length with sequelize-cli
- How to use sequelize(mysql) to count datas with angularjs + nodejs?
- How do I eager load multiple foreign keys including an or query from the same table, in Sequelize?
- Node.js Sequelize virtual column pulling value from other model
- user.setRole is not a function using sequlize postgres
- sequelize error model is not associated to another model
- Sequelize says instanceMethod is not defined
- Sequelize Authentication cannot complete
- Optimizing queries on related tables in Sequelize
- Sequelize two relationships of the same class
- findAll() from Sequelize doesn't get
- squelize associations: query the last createdAt association from many to many association
- Sequelize: How to undo migrations for dropped tables?
- Cannot register with password encrypt
- Named associations with sequelize.js
- sequelizejs update doesn't ignore null values