0

I'm starting a project using NodeJS. I did few Javascript classes and they say, that the all browsers support ES6.

I found this question here, that was asked 3 years ago and the last answer was made in 2015 and edited in 2016. The technology moves on pretty fast, so i would like to know, if this still the case in 2018.

User121018
  • 23
  • 5
  • Are you targeting node.js for server side code? – front_end_dev Nov 10 '18 at 15:16
  • Because it’s still an experimental feature in Node, I would recommend avoiding ES modules unless there’s a specific advantage you’re looking to gain with them (e.g. a static analysis tool that only supports `import`). `require` is pretty great already and you’ll certainly be using packages based around it – may as well not introduce interop considerations. – Ry- Nov 10 '18 at 15:16
  • `import` are still in experimental stage those things can change in future so better go with officially supported `require` for now. – front_end_dev Nov 10 '18 at 15:20
  • 1
    This is a duplicate of previous question. If you believe answers are missing something, consider collecting some rep and putting a bounty on that question. *the last answer was made in 2015 and edited in 2016* - no, last answers were posted a year ago and they are up to date. – Estus Flask Nov 10 '18 at 15:21
  • I will use require then, i don't trust experimental things. – User121018 Nov 10 '18 at 15:27

1 Answers1

0

Copying my answer from that old post with all the high vote, old info...

The most important thing to know is that ES6 modules are, indeed, an official standard, while CommonJS (Node.js) modules are not.

In 2019, ES6 modules are supported by 84% of browsers. While Node.js puts them behind an --experimental-modules flag, there is also a convenient node package called esm, which makes the integration smooth.

Another issue you're likely to run into between these module systems is code location. Node.js assumes source is kept in a node_modules directory, while most ES6 modules are deployed in a flat directory structure. These are not easy to reconcile, but it can be done by hacking your package.json file with pre and post installation scripts. Here is an example isomorphic module and an article explaining how it works.

isysd
  • 371
  • 2
  • 4