Tuesday, February 20, 2018

Using ECMAScript 6 modules

This may be obvious to everyone else, but today I found myself constructing a toy HTML/JS example and wanting to use the new hotness of ECMAScript 6 Modules.

I constructed the following page.

This refused to work. I kept getting

 ReferenceError: greetCustomer is not defined 

Reading the docs a little more, I decided to change it. I changed my script tag to type module and removed the onready function bit. No joy.

I tried importing directly, using an example I'd seen. Now I got:

SyntaxError: import not found: getUserPreferredLanguage

I finally got things working with the following

It seems like importing modules via the destructuring syntax by default is not the way to go.