Comments (11)
Thanks @akhileshk, that comment you linked too isn't too helpful but I think I may have found your problem. It looks like you need to tell babel-eslint
to parse your files in 'script' mode, not 'module' mode. The configuration section in the README states how to do that. Let me know if that helps.
To clear up some things in the comment:
await is a reserved word in ES6 modules,
only at the module top-level (where the EDIT: import
/export
declarations are), but not inside function bodies (spec). Babel is non-compliant in this respect.await
is reserved everywhere in ES6 modules as clarified by the async/await proposal champion here.
ES6 modules, which is what Babel expects all files to be.
babel supports both 'script' and 'module' parsing modes. I haven't seen your source code but I'm guessing since you are using asyncawait
that you don't use a transpiler, so you are writing var foo = require('foo')
rather than import foo from 'foo'
. The latter format is what babel calls a 'module', since it's using ES6 module format. The former is the CommonJS format that node.js natively supports, this format is what babel calls a 'script'.
The easiest solution to your problem would be to use real async functions instead of that module.
Perhaps. To use ES async/await today, you need a transpilation step in your project, which may be a factor in what's 'easiest'. In the long term, when no transpiler is needed, it's probably a slam-dunk to just use ES async functions. Even then asyncawait can do a number of things ES async functions can't, like awaiting more than one stack level deep, which is sometimes useful in asynchronous functional programming. YMMV.
from asyncawait.
I solved my problem that I was working on at the time using Promise.reduce() to basically run a group of promises in sequence.
If only AWS Lambda supported Node 8 where await is natively supported then my life would be a lot easier! Oh well.
Thank you for the response. I appreciate it.
from asyncawait.
Hi @mateeyow,
Sorry for the delay, I've been travelling.
Since I'm not an eslint user, would you mind explaining in a little more detail what you are wanting to do?
from asyncawait.
I am running into similar problem, this is the error I get "Parsing error: Unexpected token". Eslint is pointing to parenthesis after await(some_method()). it is getting confuse with ES7 await call without any parenthesis.
from asyncawait.
await
is not a reserved word inside function bodies, even in 'ES7', so it's strange that eslint would have a rule about it. Can it be switched off?
from asyncawait.
I am going to ask the question on eslint forum, I believe it's reporting error because it expect es7 style await as follow:
await someAsyncFunction()
//rather than
await ( someAsyncFunction())
from asyncawait.
await (someAsyncFunction())
would be a valid expression even with with ES async/await, so it's still unclear why there would be a parsing error.
from asyncawait.
here is the discussion thread at babel-eslint forum.
babel/babel-eslint#319 (comment)
from asyncawait.
This makes this library near impossible to use. Basically we can't use this library in Node 6+ in a module then, since await is a reserved keyword and it doesn't support export/import ES6 modules. Right?
FWIW I'm getting this error (await is a reserved word) without Babel just in plain jane Node 6.10.3.
from asyncawait.
@rsshilli I would recommend switching to native async/await when you can. You could also try importing the await
function using a non-reserved name, eg _await
or AWAIT
or whatever. If you were really keen to do that for some reason, I could release a new version that doesn't use await
anywhere internally.
from asyncawait.
@rsshilli I use async/await on AWS Lambda by transpiling using TypeScript. You could do the same with Babel.
from asyncawait.
Related Issues (20)
- Fibers are more flexible(?) HOT 18
- Use with ES6 classes #2 HOT 1
- Not working on nw.js HOT 1
- Error: await functions, yield functions, and value-returning suspendable functions. HOT 1
- setTimout example? HOT 2
- Unexpected token function HOT 6
- Fiber not running HOT 1
- why so long time require this two packages? HOT 1
- Extra parentheses? HOT 2
- fibers v1.0.16 dependency breaks node 4.x HOT 1
- Using a for loop HOT 2
- await inside an awaited function
- Stuck within await()... HOT 2
- Installation issue on node version 9.0.0 HOT 1
- Using forEach with Callbacks function
- Not an issue, just a thank you. HOT 1
- asyncawait fails to build on Ubuntu 16.04.4 LTS HOT 3
- Examples in typescript HOT 1
- Upgrade fibers package for nodejs 10.x or 12.x HOT 6
- Await behavior in non Async function or normal function HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from asyncawait.