Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

await is only valid in async function #75

Open
adamcoulombe opened this issue Apr 23, 2021 · 2 comments
Open

await is only valid in async function #75

adamcoulombe opened this issue Apr 23, 2021 · 2 comments

Comments

@adamcoulombe
Copy link

adamcoulombe commented Apr 23, 2021

Description

await is only valid in async function when running getting started example in readme

Steps to Reproduce

create a node app with the following code (copied from readme):

const Twitter = require('twitter-v2');

const client = new Twitter({
    bearer_token:  //bearer_token

  });

const { data } = await client.get('tweets', { ids: '1228393702244134912' });
console.log(data);

Expected behavior:

should log the output of the tweet

Actual behavior:

console error:
await is only valid in async function

Reproduces how often:

100%

Versions

^1.1.0

Additional Information

@adamcoulombe
Copy link
Author

Await constant needs to go in an async function in order for it to work like so:

async function getTweets(){
    const { data } = await client.get('tweets', { ids: '1228393702244134912' });
    return data
}
getTweets().then(tweets=>{
    console.log(tweets);
});

Docs should really be updated to reflect this since it errors out of the box with the example that is given

@hubgit
Copy link

hubgit commented Aug 13, 2021

If the file has a .mjs extension and import is used instead of require, then top-level await is allowed:

import Twitter from 'twitter-v2'

...

const { data } = await client.get('tweets', { ids: '1228393702244134912' })
console.log(data)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants