SyntaxError: await is only valid in async functions and the top level bodies of modules
Closed this issue · 1 comments
rzelnik commented
I tried to install hyperbee and run the usage example (as it is). It returns me this error message:
$ node hyperbee-usage.js
/home/user/hyperbee-usage.js:8
await db.put('key', 'value')
^^^^^
SyntaxError: await is only valid in async functions and the top level bodies of modules
at wrapSafe (node:internal/modules/cjs/loader:1024:16)
at Module._compile (node:internal/modules/cjs/loader:1072:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
at Module.load (node:internal/modules/cjs/loader:973:32)
at Function.Module._load (node:internal/modules/cjs/loader:813:14)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
at node:internal/main/run_main_module:17:47
pfrazee commented
Node 14.8 added “top level await” so that the snippet should work as is. If you can’t upgrade, wrap the code in an async function
… On Dec 22, 2020, at 11:29 PM, Robert Zelnik ***@***.***> wrote:
I tried to install hyperbee and run the usage example (as it is). It returns me this error message:
$ node hyperbee-usage.js
/home/user/hyperbee-usage.js:8
await db.put('key', 'value')
^^^^^
SyntaxError: await is only valid in async functions and the top level bodies of modules
at wrapSafe (node:internal/modules/cjs/loader:1024:16)
at Module._compile (node:internal/modules/cjs/loader:1072:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
at Module.load (node:internal/modules/cjs/loader:973:32)
at Function.Module._load (node:internal/modules/cjs/loader:813:14)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
at node:internal/main/run_main_module:17:47
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.