Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

155
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda