title: Error: No Sequelize instance passed in Nodejs
body: <p>I'm having this problem when I try to start my application or run some route. I can't understand why. Can anyone help?</p>
  <p>The full error:</p>
  <pre><code>Error: No Sequelize instance passed
      at Function.init (D:\repo\lbr\node_modules\sequelize\dist\lib\model.js:1:13622)
      at initUser (D:\repo\lbr\db\models\USERS\user.js:20:7)
      at Object.&lt;anonymous&gt; (D:\repo\lbr\db\lbDB.js:33:8)
      at Module._compile (node:internal/modules/cjs/loader:1101:14)
      at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
      at Module.load (node:internal/modules/cjs/loader:981:32)
      at Function.Module._load (node:internal/modules/cjs/loader:822:12)
      at Module.require (node:internal/modules/cjs/loader:1005:19)
      at require (node:internal/modules/cjs/helpers:102:18)
      at Object.&lt;anonymous&gt; (D:\repo\lbr\controllers\UserController.js:1:16)
  </code></pre>
  <p>My app.js in the root of the directory, where the routes are configured:</p>
  <pre><code>const express = require(&quot;express&quot;);
  const cors = require(&quot;cors&quot;);
  const cookieParser = require(&quot;cookie-parser&quot;);
  
  const app = express();
  
  const users = require(&quot;./routes/users&quot;);
  
  app.use(express.json());
  app.use(express.urlencoded({ extended: false }));
  app.use(cookieParser());
  app.use(cors({ origin: &quot;*&quot;, optionsSuccessStatus: 200 }));
  
  app.use(&quot;/users&quot;, users);
  
  module.exports = app;
  </code></pre>
  <p>/routes/users.js</p>
  <pre><code>const express = require(&quot;express&quot;);
  
  const { listUsers, addUsers, deleteUsers, updateUsers } = require(&quot;../controllers/UserController&quot;);
  
  const router = express.Router();
  
  router.get(&quot;/users&quot;, listUsers);
  router.post(&quot;/users&quot;, addUsers);
  router.put(&quot;/users/:id&quot;, updateUsers);
  router.delete(&quot;/users/:id&quot;, deleteUsers);
  
  module.exports = router;
  </code></pre>
  <p>user controller:</p>
  <pre><code>const models = require(&quot;../db/lbDB&quot;);
  
  /**
   * @param {import(&quot;express&quot;).Request} req
   * @param {import(&quot;express&quot;).Response} res
   */
  async function listUsers (req, res) {
      try {
          res.status(200).send(&quot;Users.&quot;);
      } catch (err) {
          console.log(err);
          res.status(500).json({ message: err.message, err });
      }
  }
      
      module.exports = { listUsers, ... };
  </code></pre>
  <p>lbDb, where is the configuration for database:</p>
  <pre><code>const Sequelize = require(&quot;sequelize&quot;);
  const configs = require(&quot;./config/config&quot;);
  
  const { initUser } = require(&quot;./models/USERS/user&quot;);
  const { initSector } = require(&quot;./models/USERS/sector&quot;);
  const { initArchives } = require(&quot;./models/ARCHIVES/archives&quot;);
  
  
  if (Sequelize.Promise) {
      Sequelize.Promise.config({
          // Enables all warnings except forgotten return statements.
          warnings: {
              wForgottenReturn: false
          }
      });
  }
  
  const env = process.env.NODE_ENV || &quot;development&quot;;
  const config = configs[env];
  
  if (config.logging)
      config.logging = console.log;
  
  /**
   * @type {Sequelize} conexão com o banco de dados.
   */
  let sequelize;
  
  const db = {
      db:sequelize,
  
      // Carrega arquivos de modelos das tabelas.
      User: initUser(sequelize),
      Sector: initSector(sequelize),
  
      Archives: initArchives(sequelize)
  };
  
  Object.keys(db).forEach(modelName =&gt; {
      if (&quot;associate&quot; in db[modelName])
          db[modelName].associate(db);
  });
  
  module.exports = db;
  </code></pre>
  <p>user model:</p>
  <pre><code>const { Model, DataTypes } = require(&quot;sequelize&quot;);
  
  class User extends Model {
      /**
       * Cria associações entre as tabelas do banco de dados.
       * @param {import(&quot;../../lbDB&quot;)} models
       */
      static associate (models) {
          User.belongsTo(models.Sector, { as: &quot;sector&quot;, foreignKey: &quot;id_sector&quot; });
          User.hasMany(models.Archives, { as: &quot;archives&quot;, foreignKey: &quot;id_archives&quot; });
      }
  }
  
  /**
   * Cria o modelo da tabela
   * @param {import(&quot;sequelize&quot;).Sequelize} sequelize conexão com o banco de dados.
   * @returns
   */
  function initUser (sequelize) {
      User.init({
          id: {
              type: DataTypes.INTEGER,
              primaryKey: true,
              autoIncrement: true
          },
  
          id_sector: {
              type: DataTypes.INTEGER,
              references: { model: &quot;sector&quot;, key: &quot;id&quot; },
              allowNull: false
          },
  
          user: DataTypes.STRING(40),
          name: DataTypes.STRING(100),
          email: DataTypes.STRING(100),
          password: DataTypes.STRING(100)
      }, {
          sequelize,
          timestamps: false,
          modelName: &quot;User&quot;,
          tableName: &quot;user&quot;,
          underscored: true
      });
  
      return User;
  }
  
  module.exports = { initUser };
  </code></pre>
  <p>These are the parts of my code where I believe I might be causing an error. I can't understand why. Sequelize seems to be configured correctly, but I can't access my route or start my application without error.</p>