5

I don't find good reasons to prefer es6 import over require in nodejs. I read this SO answer but it lists the difference between import/require that does not answer my question.

Right now:

  • import has many issues for those modules that do not exports.default the features
  • if an application support LTS versions, nodejs has limited support for import - like dynamic import (and/or it requires esm modules to work or tricky solutions)
  • if the application doesn't need to work on browsers you are not forced to switch to es6-imports
  • this feature will be marked as stable from October 2020 with nodejs 14

So, could you help me to understand:

  • what are the right/sensible use cases to migrate an application codebase from commonjs?
  • when migrating an application codebase from commonjs worth it? - I think when node10 will be at end-of-life

And also, as a module maintainer, is the benefit to migrating the codebase relative the in-browser execution only?

Manuel Spigolon
  • 11,003
  • 5
  • 50
  • 73

0 Answers0