ecmascript 6 - How to use ES6 module system in my case? -


all:

i pretty new es6 module system, have files like:

cmod.js

export var name = "hello2"; 

main.js

import name './cmod.js'; console.log(name); 

after run transpile :

babel ./*.js  --out-dir js/ --watch 

i wonder why result undefined? tried find answer from: https://developer.mozilla.org/en-us/docs/web/javascript/reference/statements/import https://developer.mozilla.org/en-us/docs/web/javascript/reference/statements/export

but seems complicated me match case.

thanks

you exporting named export, importing default one. should using either

// cmod.js export var name = "hello2"; // useful multiple exports 

// main.js import { name } './cmod.js'; console.log(name); 

or

// cmod.js export default "hello2"; // useful single-value exports 

// main.js import name './cmod.js'; console.log(name); 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -