balena-io-modules / drivelist

List all connected drives in your computer, in all major operating systems
Apache License 2.0
242 stars 90 forks source link

SyntaxError: await is only valid in async function #366

Open karl0ss opened 4 years ago

karl0ss commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

Duplicate of #365 ?