1

I am migrating my code from commonJS to es6 as I have to upgrade my node version to 16+.

But, I got stuck here.

  module.exports[path.parse(file).name] = sequelize.import(dir+'/'+path.parse(file).name);

I need to convert it to es6 syntax. Tried to google it, but couldn't find anything.

koushik deb
  • 158
  • 10
  • You can't, really. ES modules require statically named exports. Where does `file` come from? – Bergi Nov 07 '21 at 13:07
  • @Bergi Exactly what I feared. I can't export dynamically, can I ? :'( The file is coming recursively inside folder and subfolder. Thanks for your reply. – koushik deb Nov 07 '21 at 17:07
  • You can't. What are you trying to do? How is this code used? – Bergi Nov 07 '21 at 17:08
  • Actually, I am trying to load some models from different folders into one. – koushik deb Nov 07 '21 at 17:10
  • btw [`sequelize.import` is deprecated](https://sequelize.org/master/manual/models-definition.html) – Bergi Nov 07 '21 at 17:10
  • "*I am trying to load some models from different folders into one.*" - then just list them explicitly. Or have that module be automatically generated for you. – Bergi Nov 07 '21 at 17:11
  • This is what I am facing right now. As it is deprecated, they are telling to use require instead of sequelize.import. But, how can I use require in es6? Is there any alternative to that? Would be a much help. Thanks – koushik deb Nov 07 '21 at 17:12
  • I am trying to list them explicitly. But as you said, sequelize.import is deprecated, and I am not able to use require in es6, Is there any alternative? – koushik deb Nov 07 '21 at 17:14
  • Have a look at https://stackoverflow.com/q/29722270/1048572 – Bergi Nov 07 '21 at 17:15
  • Sure, thanks. Will look into it. – koushik deb Nov 07 '21 at 17:18

0 Answers0