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

SyntaxError: await is only valid in async function #366

Open
karl0ss opened this issue Mar 4, 2020 · 2 comments
Open

SyntaxError: await is only valid in async function #366

karl0ss opened this issue Mar 4, 2020 · 2 comments

Comments

@karl0ss
Copy link

karl0ss commented Mar 4, 2020

Using your example on npmjs.org

const drivelist = require('drivelist');
 
const drives = await drivelist.list();
console.log(drives);

Gives me

const drives = await drivelist.list();
               ^^^^^

SyntaxError: await is only valid in async function
    at Module._compile (internal/modules/cjs/loader.js:891:18)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
    at Module.load (internal/modules/cjs/loader.js:811:32)
    at Function.Module._load (internal/modules/cjs/loader.js:723:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)
    at internal/main/run_main_module.js:17:11
$ node -v
v12.14.1
@karl0ss
Copy link
Author

karl0ss commented Mar 4, 2020

Only seems to work is i wrap in a async function

const drivelist = require('drivelist');
 
async function test () {
const drives = await drivelist.list();
console.log(drives);
}

test()

@lurch
Copy link
Contributor

lurch commented Mar 4, 2020

Duplicate of #365 ?

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