You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Is there a way to use async/await with angular-cli? #4554
I tested it with non-beta @angular 2 stack as well:
@angular/cli: 1.0.0-beta.31
node: 6.9.5
os: win32 x64
@angular/common: 2.4.7
@angular/compiler: 2.4.7
@angular/core: 2.4.7
@angular/forms: 2.4.7
@angular/http: 2.4.7
@angular/platform-browser: 2.4.7
@angular/platform-browser-dynamic: 2.4.7
@angular/router: 3.4.7
@angular/cli: 1.0.0-beta.31
@angular/compiler-cli: 2.4.7
Manually updating my Typescript to 2.1.0 allows me to use async/await on code even on es5, and it does build with -prod flag then (whereas es6 doesn't).
My project was small - the Hero Manager tutorial, so it might miss some obvious, but I could repro the issue present here and I could solve the working version of async/await in that project.
There were some probably unnecessary experiments. The final step that succeeded for me was uninstalling Typescript and reinstalling it as 2.1.0 (modified just package.json ran npm install).
Edit: For me it was also broken with 2.0.3 Typescript version; in my case the WebStorm editor was first to complain about async/await if I had es5 enabled. After updating Typescript, WebStorm was happy and so was the build chain still with es5.
@alexbyk Thank you for pointing this topic out. I was interested in it as well, but it wasn't that much brought up elsewhere. And then I was just about in proper situation to start from scratch and explore :-)
I wanted to find a solution that stays mainly on angular-git; with as little modifications as possible - and I'm glad we did :-)
EDIT: Should have asked this question to my rubber duck. Because I found the obvious flaw in this code.
browser.executeScript should be browser.executeAsyncScript !
angular-automatic-lock-bot commented on Sep 7, 2019
Activity
hccampos commentedon Feb 9, 2017
I think you will have to wait for Angular 4 to be able to use TS >= 2.1 Check #3525
deebloo commentedon Feb 10, 2017
the newest version of the cli (beta-31) should have support for generating a project with angular 4 which mean you can safely use type 2.1
filipesilva commentedon Feb 10, 2017
Closing as answered.
alexbyk commentedon Feb 10, 2017
Actually not answered at all((( I already use TS 2.1.5. How switching to Angular 4 could change things with UglifyJS?
kallex commentedon Feb 12, 2017
I played about this; actually Typescript 2.1.0 works with es5. I tested grabbing cli beta-31 and applied -ng4 to get 4.0.0-beta.7
So async/await work without having to change target to es6.
kallex commentedon Feb 12, 2017
I tested it with non-beta @angular 2 stack as well:
@angular/cli: 1.0.0-beta.31
node: 6.9.5
os: win32 x64
@angular/common: 2.4.7
@angular/compiler: 2.4.7
@angular/core: 2.4.7
@angular/forms: 2.4.7
@angular/http: 2.4.7
@angular/platform-browser: 2.4.7
@angular/platform-browser-dynamic: 2.4.7
@angular/router: 3.4.7
@angular/cli: 1.0.0-beta.31
@angular/compiler-cli: 2.4.7
Manually updating my Typescript to 2.1.0 allows me to use async/await on code even on es5, and it does build with -prod flag then (whereas es6 doesn't).
My project was small - the Hero Manager tutorial, so it might miss some obvious, but I could repro the issue present here and I could solve the working version of async/await in that project.
alexbyk commentedon Feb 12, 2017
@kallex Could you please share your tsconfig for ng2+es5+async/awat + prod flag? Because when I change target to 'es5' async/await become broken
kallex commentedon Feb 12, 2017
@alexbyk here's full repo.
https://github.com/kallex/herotutorial
There were some probably unnecessary experiments. The final step that succeeded for me was uninstalling Typescript and reinstalling it as 2.1.0 (modified just package.json ran npm install).
Edit: For me it was also broken with 2.0.3 Typescript version; in my case the WebStorm editor was first to complain about async/await if I had es5 enabled. After updating Typescript, WebStorm was happy and so was the build chain still with es5.
alexbyk commentedon Feb 12, 2017
@kallex thanks a lot. I'll check it out tomorrow
alexbyk commentedon Feb 13, 2017
@kallex thanks again. Indeed I reinstalled all packages and that helped
kallex commentedon Feb 13, 2017
@alexbyk Thank you for pointing this topic out. I was interested in it as well, but it wasn't that much brought up elsewhere. And then I was just about in proper situation to start from scratch and explore :-)
I wanted to find a solution that stays mainly on angular-git; with as little modifications as possible - and I'm glad we did :-)
kianfang commentedon Mar 22, 2017
@kallex Thanks.I had solved to set package.typescript as 2.1 :-)
the async/await become to normal function.
jmls commentedon Apr 13, 2017
I am also having issues with trying to get await to work, and can't figure it out.
typescript 2.2.2
tsconfig:
"@angular/cli": "^1.0.0",
Within a class I am trying to write this
but am getting the compile error
what am I missing ? thanks!
arlowhite commentedon Apr 24, 2017
Just FYI, the function you are using await in must be tagged with async
The error message is not very helpful at suggesting this.
Thommas commentedon May 22, 2017
The following worked for me:
My problem is that async/await randomly fails to wait for Angular to resolve a click, or a change of URL.
If I run each test independently, then everything is fine and quick.
I used to use browser.sleep one year ago with Angular1.x, I'm glad we can use await/async, that's clearly the future !
arlowhite commentedon May 22, 2017
@Thommas Maybe not relevant, but Angular 4.1.3 made a change to Promises used by the Router
https://github.com/angular/angular/blob/master/CHANGELOG.md
So maybe awaiting a Router's Promise was broken previous to 4.1.3?
Thommas commentedon May 23, 2017
Just updated to 4.1.3, same behavior.
I've tried using browser.sleep to fix some tests, but I still end up with 2/3 random tests failed out of 35 tests.
When I run tests one by one, they all pass without any problem.
A typical test looks like this:
e2e-spec.ts
app.po.ts
EDIT: Should have asked this question to my rubber duck. Because I found the obvious flaw in this code.
browser.executeScript should be browser.executeAsyncScript !
angular-automatic-lock-bot commentedon Sep 7, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.