Closed kjoedion closed 1 year ago
forEach is sync and cannot return a promise, so you're not awaiting the async callback passed to it. Use array.map and Promise.all
forEach is sync and cannot return a promise, so you're not awaiting the async callback passed to it. Use array.map and Promise.all
Thank you, I didn't even think of that. My bad for blaming sequelize.
I changed my code to a for
instead and it works:
const files = await globby([
'../models/**/*.js',
'../routes/**/*.js',
], {
cwd: './app/entries',
})
for (const file of files) {
await import(file)
}
await db.sync({ alter: true })
Using dynamic imports in order to define models does not work. It works fine when manually declaring the imports, but I'd prefer just being able to create model files in a directory and my app knowing they exist dynamically.
db.js
:server.js
:The models do not get defined this way. Whats funny is my
routes
for express are done in the same way, and they work fine.If I change it to non-dynamic imports, the sequelize definitions work fine:
Why doesn't sequelize pick up the definitions when done via dynamic imports as opposed to manual imports?