Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
Exported sequelize instance is undefined in Model imports

Good evening.

I have an express server. The main script of the server has the following export:

export const sequelize = new Sequelize(
  'postgres', config.db_user, config.db_password, {
    host: 'localhost',
    port: config.db_port,
    dialect: 'postgres'
  })

And I'm trying to create a file structure that allows for each model to be define in a different file. Right now I have a Sequelize model defined like this:

import { Test } from "@api-models";
import { DataTypes } from "sequelize";
import { sequelize } from "../main";

Test.init({
    id: {
        type: DataTypes.INTEGER,
        autoIncrement: true,
        primaryKey: true
    },
    name: {
        type: DataTypes.STRING,
        allowNull: false
    },
    joinedDate: {
        type: DataTypes.DATE
    }
}, {sequelize: sequelize})

export default Test

But this doesn't work, as the sequelize import in the model file returns undefined, and the initialization fails with the following error message:

Error: No Sequelize instance passed

I've been investigating for a while, but most answers seem to rely on node or JS exporting syntax to specify the order of execution, rather than ES6 imports/exports. What would be the proper approach to do this?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

This was solved, what was happening is that there was a circular dependency between the router, the models and the main file which initialized both.

Moving the Sequelize initialization logic to a different file solved the issue.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!