BestBuy / api-playground

The Best Buy API Playground is an API training tool for students, educators and other learners to explore the possibilities of a fully functional RESTful API in a simple, non-production environment.
Other
260 stars 104 forks source link

New error - sequelize.import is not a function while npm start #26

Open akshaya-kd opened 3 years ago

akshaya-kd commented 3 years ago

Getting Below error while performing npn start

D:\BestBuyAPI\api-playground>npm start

api-playground@1.1.0 start node src/

D:\BestBuyAPI\api-playground\src\db\index.js:36 var model = sequelize['import'](path.join(__dirname, file)); ^

TypeError: sequelize.import is not a function at D:\BestBuyAPI\api-playground\src\db\index.js:36:38 at Array.forEach () at Function.setupDatabase (D:\BestBuyAPI\api-playground\src\db\index.js:35:6) at Function.configure (D:\BestBuyAPI\api-playground\node_modules\feathers\lib\application.js:150:8) at Function.module.exports (D:\BestBuyAPI\api-playground\src\services\index.js:11:7) at Function.configure (D:\BestBuyAPI\api-playground\node_modules\feathers\lib\application.js:150:8) at Object. (D:\BestBuyAPI\api-playground\src\app.js:31:4) at Module._compile (node:internal/modules/cjs/loader:1109:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10) at Module.load (node:internal/modules/cjs/loader:989:32)

akshaya-kd commented 3 years ago

Please refer the below index file details

  1. fs.readdirSync(__dirname)
  2. .filter(function (file) {
  3. return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
  4. })
  5. .forEach(function (file) {
  6. var model = sequelize['import'](path.join(__dirname, file));
  7. db[model.name] = model;
  8. });
anktyagi commented 2 years ago

Replace var model = sequelize['import'](path.join(dirname, file)); to var model = require(path.join(dirname, file))(sequelize, Sequelize.DataTypes);