Sails: SyntaxError: await is only valid in async function in sails console

Created on 12 Apr 2018  路  3Comments  路  Source: balderdashy/sails

Sails version:1.0.1
Node version:9.10.1
NPM version:5.6.0
DB adapter name: N/A
DB adapter version: N/A
Operating system:OS X




I wonder if you plan to support await in sails console.
All sample code from documentation doesn't work in console and throws this error:
SyntaxError: await is only valid in async function

Most helpful comment

Thanks @hamzaOp! @danil-z, as of right now the Node REPL doesn't support await outside of an async function (although interestingly enough Chrome dev tools do!). Since sails console uses the Node REPL, it has this same constraint. You can see the discussion about this in the Node repo itself here.

In the meantime, you can run async code in the console by wrapping it in a self-calling async function, e.g.:

(async () => { 
   console.log(await User.find({ name: 'joe' })); 
})()

All 3 comments

@danil-z Thanks for posting, we'll take a look as soon as possible.


For help with questions about Sails, click here. If you’re interested in hiring @sailsbot and her minions in Austin, click here.

This is not related to the sails console, the await operator is valid only in async functions , take a look here.

Thanks @hamzaOp! @danil-z, as of right now the Node REPL doesn't support await outside of an async function (although interestingly enough Chrome dev tools do!). Since sails console uses the Node REPL, it has this same constraint. You can see the discussion about this in the Node repo itself here.

In the meantime, you can run async code in the console by wrapping it in a self-calling async function, e.g.:

(async () => { 
   console.log(await User.find({ name: 'joe' })); 
})()
Was this page helpful?
0 / 5 - 0 ratings