Use of Asynchronous Keywords in our Sage Environment

Hi,

I recently tried to update some third-party JavaScript code in our application which uses Sage. This update uses keywords async and await in function declaration. When I attempted a yarn build I got errors. The errors are eliminated with async and await are removed.

The only babel configuration I saw was in various node modules, for example one preset was es2015.

Can anyone comment on have trouble using asynchronous functions or ES8 JavaScript features in their Sage environment? Do you have any suggestions on updating the build process? Our build process works well for most things I am concerned about breaking it.

Looking into this I also noted our webpack version is older. I didn’t see any webpack specific babel configuration. A yarn why webpack suggests our webpack version is 2.7.0.

Thanks,

Dan

Please read How to best ask questions on this forum

What version of Sage?

What is the code that is erroring?

What is the error?

Hi Ben,

Apologies for violating forum standards with my post. I am not sure how much this information will clarify, but thanks for looking at it.

Version of Sage: I am actually not sure. It is customized and my organization gave it a version 1.0, but it is not version 1 of Sage. We use Sage v9.0, third edition PDF from February 2018 (written by you) as our reference.

What is the code that is erroring:

            window.OneSignalDeferred = window.OneSignalDeferred || [];
            OneSignalDeferred.push( async function(OneSignal) {
                await OneSignal.init(window._oneSignalInitOptions);
            });

This is relatively new code from OneSignal. Removing async and await avoid the error.

What is the error:

The error resulting from the yarn build is below. Note that removing the JavaScript keywords, async and await, gets around the error.

ERROR in ./scripts/routes/common.js
Module build failed:
221 : await OneSignal.init({});
222 : });
223 : */
224 : window.OneSignalDeferred = window.OneSignalDeferred || ;
225 : OneSignalDeferred.push( async function(OneSignal) {
^
Unexpected token (225:34)
@ ./scripts/main.js 7:0-37
@ multi ./scripts/main.js ./styles/main.scss

Thanks,

Dan

Sage 9’s build system is very old and uses Buble which doesn’t support async/await

There’s a couple of old topics on here about it, but I don’t believe anyone has gotten it to work

Is it possible for you to migrate your old theme to a newer one based on Sage 10?