Code Monkey home page Code Monkey logo

Comments (11)

yortus avatar yortus commented on August 17, 2024 3

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 import/export declarations are), but not inside function bodies (spec). Babel is non-compliant in this respect. EDIT: 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.

rsshilli avatar rsshilli commented on August 17, 2024 1

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.

yortus avatar yortus commented on August 17, 2024

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.

akhileshk avatar akhileshk commented on August 17, 2024

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.

yortus avatar yortus commented on August 17, 2024

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.

akhileshk avatar akhileshk commented on August 17, 2024

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.

yortus avatar yortus commented on August 17, 2024

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.

akhileshk avatar akhileshk commented on August 17, 2024

here is the discussion thread at babel-eslint forum.
babel/babel-eslint#319 (comment)

from asyncawait.

rsshilli avatar rsshilli commented on August 17, 2024

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.

yortus avatar yortus commented on August 17, 2024

@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.

Seikho avatar Seikho commented on August 17, 2024

@rsshilli I use async/await on AWS Lambda by transpiling using TypeScript. You could do the same with Babel.

from asyncawait.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.