0
votes

I have a Nodejs, Express, Sequelize, and Angular app and everything is working. I needed to use sequelize-hierarchy and when I run the server I got the following error :

    internal/modules/cjs/loader.js:969
      throw err;
      ^
    
    Error: Cannot find module 'Sequelize-hierarchy'
    Require stack:
    - D:\Projets\mon-plaisir\src\app\models\index.js
    - D:\Projets\mon-plaisir\serveur-node-postgres\serveur.js
        at Function.Module._resolveFilename (internal/modules/cjs/loader.js:966:15)
        at Function.Module._load (internal/modules/cjs/loader.js:842:27)
        at Module.require (internal/modules/cjs/loader.js:1026:19)
        at require (internal/modules/cjs/helpers.js:72:18)
        at Object.<anonymous> (D:\Projets\mon-plaisir\src\app\models\index.js:7:1)
        at Module._compile (internal/modules/cjs/loader.js:1138:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
        at Module.load (internal/modules/cjs/loader.js:986:32)
        at Function.Module._load (internal/modules/cjs/loader.js:879:14)
        at Module.require (internal/modules/cjs/loader.js:1026:19) {
      code: 'MODULE_NOT_FOUND',
      requireStack: [
        'D:\\Projets\\mon-plaisir\\src\\app\\models\\index.js',
        'D:\\Projets\\mon-plaisir\\serveur-node-postgres\\serveur.js'
      ]
    }

The package.json file contains sequelize-hierarchy in the dependencies.

And in node_modules I have the sequelize-hierarchy folder

And in the index.js file:

    const dbConfig = require("../config/db.config");
    
    const Sequelize = require('sequelize');
    require('Sequelize-hierarchy')(Sequelize);
    
    const sequelize = new Sequelize(dbConfig.DB, dbConfig.USER, dbConfig.PASSWORD,
      {
          host: dbConfig.HOST,
          dialect: dbConfig.dialect,
          define: {
            freezeTableName: true,
            underscored: false,
            raw: true
          },
    
          pool: {
            max: dbConfig.pool.max,
            min: dbConfig.pool.min,
            acquire: dbConfig.pool.acquire,
            idle: dbConfig.pool.idle
          }
      }
    );
    
    const db = {};
    
    db.Sequelize = Sequelize;
    db.sequelize = sequelize;

Thanks for your help because I just spent a lot of time and I can't find the solution.

2

2 Answers

0
votes

Seems like everything is fine but you are using capital 'S' to load sequelize-hierarchy Use small 'sequelize-hierarchy' in require.

const Sequelize = require('sequelize');
require('sequelize-hierarchy')(Sequelize);
0
votes

I performed the operations and I still have the same error message. During the installation (, I have the following warning: npm WARN [email protected] No repository field.

Remove

D:\Projets\mon-plaisir\serveur-node-postgres>npm remove sequelize-hierarchy
npm WARN [email protected] No repository field.

audited 92 packages in 0.888s
found 0 vulnerabilities

Install

D:\Projets\mon-plaisir\serveur-node-postgres>npm install sequelize-hierarchy
npm WARN [email protected] No repository field.

+ [email protected]
added 4 packages from 2 contributors and audited 96 packages in 1.109s
found 0 vulnerabilities