Explain please can not understand what I'm doing wrong. There is such code:

Exporting an anonymous function by default. File flash-message.js :

export default function(message){ console.log(message); } 

Next, I import this thing into the app.js file:

 import flashMessage from './flash-message'; flashMessage("hello!"); 

And I connect both modules to index.html :

 <!doctype html> <html> <body> <script src="./flash-message.js"></script> <script src="./app.js"></script> </body> </html> 

In the manual for which I do, everything works. My chrome writes an error:

flash-message.js: 1 Uncaught SyntaxError: Unexpected token export

app.js: 1 Uncaught SyntaxError: Unexpected token import

There are two points that are not clear to me:

  1. Why in the tutorial, on video, such a structure works. And chrome does not produce errors.

  2. Why if I translate this code using babel ("presets": ["es2015"]). In the node interpreter, the code works, but in chrome it’s still an error.

  • export and import have not yet entered into processing by browsers. Be sure to es6 code needs to be compiled for example using babel. You just get an error that the browser does not know what you are talking about) - Vasily Barbashev
  • what kind of tutorial? - Grundy
  • @ Vasily Barbashev I also say further that I compile it, after that it works on the node and not in the browser - spectre_it
  • @ stas0k went through it, but there were no problems. What does it mean at the node works, but the browser does not? Noda server, browser client side. And their interpreters are slightly different. After compiling what code your browser does not understand, add to the question what comes to the sorts - Vasily Barbashev

0