Async/await in plugin: works in dev instance, not in docker instance

AI-generated summary

The discussion revolves around an issue with async/await in plugins not working in a Docker instance, but working in a development instance. jack2 initially reported the error and found that removing async/await fixes the issue. It was suggested that naming plugin files with a .js.es6 extension could solve the problem, but this didn’t seem to be the case for jack2 and spirobel.

eviltrout explained that async/await is not currently supported in Discourse, and while it may work in modern browsers, it’s not enabled for server-side compilation. There are plans to move towards using Ember CLI, which may resolve this issue as a side effect, with an estimated solution timeline of around 8 months, as mentioned by sam. Until then, removing async/await from plugin code seems to be the workaround, as confirmed by joffreyjaffeux.

I get this error when installing a plugin in a docker instance:

Compressing: plugin-third-party-ea46d31326df4fb4ed1d79ef5ecad5179b0512d15492b09e348b67b027cced32.js
uglifyjs '/var/www/discourse/public/assets/_plugin-third-party-ea46d31326df4fb4ed1d79ef5ecad5179b0512d15492b09e348b67b027cced32.js' -p relative -c -m -o '/var/www/discourse/public/assets/plugin-third-party-ea46d31326df4fb4ed1d79ef5ecad5179b0512d15492b09e348b67b027cced32.js' --source-map-root '/assets' --source-map '/var/www/discourse/public/assets/plugin-third-party-ea46d31326df4fb4ed1d79ef5ecad5179b0512d15492b09e348b67b027cced32.js.map' --source-map-url '/assets/plugin-third-party-ea46d31326df4fb4ed1d79ef5ecad5179b0512d15492b09e348b67b027cced32.js.map'
Parse error at _plugin-third-party-ea46d31326df4fb4ed1d79ef5ecad5179b0512d15492b09e348b67b027cced32.js:637,7
	async function onEvent(container, event) {
	      ^
SyntaxError: Unexpected token: keyword (function)
    at JS_Parse_Error.get (eval at <anonymous> (/usr/lib/node_modules/uglify-js/tools/node.js:27:1), <anonymous>:86:23)
    at /usr/lib/node_modules/uglify-js/bin/uglifyjs:384:40
    at time_it (/usr/lib/node_modules/uglify-js/bin/uglifyjs:620:15)
    at /usr/lib/node_modules/uglify-js/bin/uglifyjs:345:9
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:511:3)

Removing async/await fixes the issue. It looks like some es6 code is sent to uglifyjs before conversion to es5.

The error doesn’t always occur. A few days ago, I retried installing several times and it finally succeeded. But now I’m stuck again.

Did you name your plugin file name.js.es6 ?

Nope, none of my plugin files are named name.js.es6.

Hence the problem, you need to name them with that extension.

My plugin has just installed correctly, at the 3rd attempt.

If you want it to compile properly, make sure they have a .js.es6 extension, then it will work everytime.

I am not even sure if we enabled async await in babel @eviltrout ? I certainly have never used it in the Discourse code base.

@Falco, if your question was about the extension of my files, then yes, I’m using .js.es6 everywhere.

We are not transpiling that. It probably works in the browser if you’re using an evergreen one, but we don’t support it yet.

We could benefit from it, I just haven’t had the time to enable it, make sure the perf is good, and start converting code.

Any news on this? Having it would be great.

We did start using this in tests, have not decided on our strategy yet for using it in production or not.

Have you made some progress on this?

@eviltrout has started a long spike at moving us towards using ember CLI. Part of the work should sort this out as a side effect.

I would expect we have this solved some time in the next 8 months.

I have this issue too
https://github.com/spirobel/projects/issues/1
I use name.js.es6 everywhere.

Does this mean I need to remove async/await?

Yes we don’t support async/await yet as explained.