# 插件中的 Async/await：在开发实例中工作，在 Docker 实例中不工作

**URL:** <https://meta.discourse.org/t/async-await-in-plugin-works-in-dev-instance-not-in-docker-instance/82363>\
**Category:** Development\
**Created:** [2018年三月6日 22:23 UTC](https://meta.discourse.org/t/async-await-in-plugin-works-in-dev-instance-not-in-docker-instance/82363 "2018-03-06T22:23:29Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![jack2](https://avatars.discourse-cdn.com/v4/letter/j/ac91a4/32.png) [@jack2](https://meta.discourse.org/u/jack2)\
**Post date:** [2018年三月6日 22:23 UTC](https://meta.discourse.org/t/async-await-in-plugin-works-in-dev-instance-not-in-docker-instance/82363/1 "2018-03-06T22:23:29Z")

</div>

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

```plaintext
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.

---

<div class="post-metadata">

**Author:** ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)\
**Post date:** [2018年三月6日 22:27 UTC](https://meta.discourse.org/t/async-await-in-plugin-works-in-dev-instance-not-in-docker-instance/82363/2 "2018-03-06T22:27:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jack2](https://avatars.discourse-cdn.com/v4/letter/j/ac91a4/32.png) [@jack2](https://meta.discourse.org/u/jack2)\
**Post date:** [2018年三月6日 22:39 UTC](https://meta.discourse.org/t/async-await-in-plugin-works-in-dev-instance-not-in-docker-instance/82363/3 "2018-03-06T22:39:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)\
**Post date:** [2018年三月6日 22:41 UTC](https://meta.discourse.org/t/async-await-in-plugin-works-in-dev-instance-not-in-docker-instance/82363/4 "2018-03-06T22:41:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jack2](https://avatars.discourse-cdn.com/v4/letter/j/ac91a4/32.png) [@jack2](https://meta.discourse.org/u/jack2)\
**Post date:** [2018年三月6日 22:44 UTC](https://meta.discourse.org/t/async-await-in-plugin-works-in-dev-instance-not-in-docker-instance/82363/5 "2018-03-06T22:44:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)\
**Post date:** [2018年三月7日 00:07 UTC](https://meta.discourse.org/t/async-await-in-plugin-works-in-dev-instance-not-in-docker-instance/82363/6 "2018-03-07T00:07:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [2018年三月7日 00:36 UTC](https://meta.discourse.org/t/async-await-in-plugin-works-in-dev-instance-not-in-docker-instance/82363/7 "2018-03-07T00:36:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jack2](https://avatars.discourse-cdn.com/v4/letter/j/ac91a4/32.png) [@jack2](https://meta.discourse.org/u/jack2)\
**Post date:** [2018年三月7日 13:39 UTC](https://meta.discourse.org/t/async-await-in-plugin-works-in-dev-instance-not-in-docker-instance/82363/8 "2018-03-07T13:39:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)\
**Post date:** [2018年三月7日 16:07 UTC](https://meta.discourse.org/t/async-await-in-plugin-works-in-dev-instance-not-in-docker-instance/82363/9 "2018-03-07T16:07:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![syl](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/syl/32/98883_2.png) [@syl](https://meta.discourse.org/u/syl)\
**Post date:** [2018年十月8日 00:16 UTC](https://meta.discourse.org/t/async-await-in-plugin-works-in-dev-instance-not-in-docker-instance/82363/10 "2018-10-08T00:16:17Z")

</div>

Any news on this? Having it would be great.

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [2018年十月8日 00:43 UTC](https://meta.discourse.org/t/async-await-in-plugin-works-in-dev-instance-not-in-docker-instance/82363/11 "2018-10-08T00:43:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![syl](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/syl/32/98883_2.png) [@syl](https://meta.discourse.org/u/syl)\
**Post date:** [2020年二月23日 16:26 UTC](https://meta.discourse.org/t/async-await-in-plugin-works-in-dev-instance-not-in-docker-instance/82363/12 "2020-02-23T16:26:13Z")

</div>

你在这方面取得了一些进展吗？

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [2020年二月24日 01:35 UTC](https://meta.discourse.org/t/async-await-in-plugin-works-in-dev-instance-not-in-docker-instance/82363/13 "2020-02-24T01:35:12Z")

</div>

@eviltrout 已经开始了一项长期任务，推动我们转向使用 Ember CLI。这项工作的一部分应该会顺带解决这个问题。

我预计我们将在未来 8 个月内解决这个问题。

---

<div class="post-metadata">

**Author:** ![spirobel](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/spirobel/32/170908_2.png) [@spirobel](https://meta.discourse.org/u/spirobel)\
**Post date:** [2020年五月2日 10:11 UTC](https://meta.discourse.org/t/async-await-in-plugin-works-in-dev-instance-not-in-docker-instance/82363/14 "2020-05-02T10:11:08Z")

</div>

我也遇到了这个问题

> <https://github.com/spirobel/projects/issues/1>
>
> Trying to enable this plugin into the current version of Discourse fails with th…e following output.
> 
> \`\`\`ruby
> 78954.470854151 Compressing: plugins/projects-fe2ea5a8cfbe65a7a4c2549cf8898efc05189a6ac16db43af79144ec69a9432a.js
> uglifyjs '/var/www/discourse/public/assets/plugins/\_projects-fe2ea5a8cfbe65a7a4c2549cf8898efc05189a6ac16db43af79144ec69a9432a.js' -m -c -o '/var/www/discourse/public/assets/plugins/projects-fe2ea5a8cfbe65a7a4c2549cf8898efc05189a6ac16db43af79144ec69a9432a.js' --source-map "base='/var/www/discourse/public/assets/plugins',root='/assets/plugins',url='/assets/plugins/projects-fe2ea5a8cfbe65a7a4c2549cf8898efc05189a6ac16db43af79144ec69a9432a.js.map'"
> Parse error at \_projects-fe2ea5a8cfbe65a7a4c2549cf8898efc05189a6ac16db43af79144ec69a9432a.js:104,21
> destroy: async function destroy(deleted\_by) {
> ^
> ERROR: Unexpected token: keyword «function», expected: punc «,»
> at JS\_Parse\_Error.get (eval at \<anonymous\> (/usr/lib/node\_modules/uglify-js/tools/node.js:18:1), \<anonymous\>:71:23)
> at fatal (/usr/lib/node\_modules/uglify-js/bin/uglifyjs:312:27)
> at run (/usr/lib/node\_modules/uglify-js/bin/uglifyjs:255:9)
> at Object.\<anonymous\> (/usr/lib/node\_modules/uglify-js/bin/uglifyjs:173:5)
> at Module.\_compile (internal/modules/cjs/loader.js:778:30)
> at Object.Module.\_extensions..js (internal/modules/cjs/loader.js:789:10)
> at Module.load (internal/modules/cjs/loader.js:653:32)
> at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
> at Function.Module.\_load (internal/modules/cjs/loader.js:585:3)
> at Function.
> \`\`\`

我到处都在使用 name.js.es6。

> **[Build software better, together](https://github.com/search?q=repo%3Aspirobel%2Fprojects+async)**
>
> GitHub is where people build software. More than 150 million people use GitHub to discover, fork, and contribute to over 420 million projects.

这是否意味着我需要移除 async/await？

---

<div class="post-metadata">

**Author:** ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)\
**Post date:** [2020年五月3日 09:43 UTC](https://meta.discourse.org/t/async-await-in-plugin-works-in-dev-instance-not-in-docker-instance/82363/15 "2020-05-03T09:43:51Z")

</div>

是的，正如已解释的那样，我们目前尚不支持 async/await。
