glimmerjs / glimmer-application

[MOVED] This package is now part of the Glimmer.js monorepo
https://github.com/glimmerjs/glimmer.js
30 stars 13 forks source link

Can't use `async` / `await` out of the box #55

Closed wycats closed 7 years ago

wycats commented 7 years ago

This is currently due to missing regeneratorRuntime.

choclaudio commented 7 years ago

Hi there! While we wait for this particular issue to be solved. What should we do in the meantime to get async/await working?

having the --web-component flag still produces the same problem. installing babel-polyfill on my project does not solve the problem. adding a babel section with includePolyfill: true in ember-cli-build.js does not solve the problem.

Any combination of the above does not seem to work.

matt-mendonca commented 7 years ago

As a quick work around, I switched the target in the .tsconfig to es5:

 {
   "compilerOptions": {
-    "target": "es6",
+    "target": "es5",
     "module": "es2015",
     "inlineSourceMap": true,
     "inlineSources": true,

If the browsers you are targeting already have promises, then that should do the trick.

Typescript will warn that you'll need to explicitly include promises (since es5 didn't have them):
An async function or method in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option.

That should be something like this:

{
   "compilerOptions": {
-    "target": "es6",
+    "target": "es5",
     "module": "es2015",
     "inlineSourceMap": true,
     "inlineSources": true,
     "moduleResolution": "node",
-    "experimentalDecorators": true
+    "experimentalDecorators": true,
+    "lib": [
+      "es2015"
+    ]
   },

However, looks like we can't manually specify extra libs in the tsconfig file with broccoli yet and adding the lib property causes the build to fail (https://github.com/tildeio/broccoli-typescript-compiler/issues/35):

The Broccoli Plugin: [broccoli-typescript-compiler] failed with:
TypeError: Cannot read property 'length' of undefined

So, don't add the lib property and just ignore the typescript warning.

Overall, not ideal, but it at least got me started.

locks commented 7 years ago

Instructions now at https://github.com/glimmerjs/glimmer-application-pipeline#enabling-use-of-async-await-in-components.