New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Class constructor model cannot be invoked without 'new' after uninstalling babel #9280

Open
ekkatharisi opened this Issue Jan 5, 2019 · 5 comments

Comments

Projects
None yet
3 participants
@ekkatharisi
Copy link

ekkatharisi commented Jan 5, 2019

Bug Report

Current Behavior
i have a trouble using babel , and when i unistalling it to use just the ES5 , it shoots this error :
TypeError: Class constructor model cannot be invoked without 'new'
this is my code :
Input Code

        const fs = require('fs');
        const path = require('path'); 
        const Sequelize = require('sequelize');
        const basename = path.basename(__filename);
        const env = 'development';
        const config = require('../config/config')[env];

           const sequelize  = new Sequelize(config.database.database_name, config.database.username, 
           config.database.password, config.database.database_config);

      var db = {
         sequelize : sequelize,
         Sequelize : Sequelize
      };

        db.sequelize.authenticate().then(() => {
        console.log('database worked !!!');


    fs.readdirSync(path.join(__dirname,'models/')).filter(file => {
        return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
    }).forEach(file => {
        var model = db.sequelize.import(path.join(__dirname,"models/", file));
        //var model = require(path.join(__dirname,"models/", file))(sequelize, Sequelize);
        db[model.name] = model;
    });

       Object.keys(db).forEach(modelName => {
           if (db[modelName].associate) {
               db[modelName].associate(db);
          }
         } );
       db.sequelize.sync({force : true}).then(res => {
           console.log('database created !!!!!!!!!');
      }).catch(err => {
           console.log(err.stack);
     })
        }).catch(error => {
            console.log(error.stack);
       });
       module.exports = db;

please what i should do now ??

Environment

  • Babel version(s): [e.g. v6.0.0, v7.0.0-beta.34]
  • Node/npm version: [e.g. Node 10.14.2/npm 6.4.1]
  • OS: [Windows 10]
  • How you are using Babel: [cli]
@babel-bot

This comment has been minimized.

Copy link
Collaborator

babel-bot commented Jan 5, 2019

Hey @ekkatharisi! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community
that typically always has someone willing to help. You can sign-up here
for an invite.

@nicolo-ribaudo

This comment has been minimized.

Copy link
Member

nicolo-ribaudo commented Jan 7, 2019

Which lines doe throw that error?
Also, I'm not sure that I understood the question: your code works when if you use Babel but doesn't work without Babel?

@ekkatharisi

This comment has been minimized.

Copy link

ekkatharisi commented Jan 7, 2019

thank you @nicolo-ribaudo for responding me, so the problem that i install BABEL in my laptop (and other pc), after that the console shoots this error in this line
var model = db.sequelize.import(path.join(__dirname,"models/", file));
after , i remove BABEL by this comande :
npm uninstall babel-cli babel-preset-es2015 babel-preset-env
npm uninstall -g babel-cli babel-preset-es2015 babel-preset-env
but the error still the same, what I want is to execute the code fine without this error.
NOTE 1: the error occurs when I use this command
node connect.js
NOTE 2: I use node version 10.13.0.
the whole project is in this repo
thank you in advance.

@nicolo-ribaudo

This comment has been minimized.

Copy link
Member

nicolo-ribaudo commented Jan 7, 2019

Maybe you can find a solution at sequelize/sequelize#7840.

Another possible solution is to transpile the sequelize module to es5.
Btw, I suggest you to use Babel 7 instead of Babel 6.

@ekkatharisi

This comment has been minimized.

Copy link

ekkatharisi commented Jan 7, 2019

but the sequelize modules are transpiled to es5, (have you see any es6 expression )
and no as i say i remove conmpletely BABEL , but the error still the same .
and thank you @nicolo-ribaudo for reference but i don't find the solution yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment