In my JavaScript program, I have:
const myFunction = async function (input) {
// do stuff
}
It runs fine on Windows 10. But same code gives error on AWS EC2 instance:
const myFunction = async function (input) {
SyntaxError: Unexpected token function
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
What do I need to do here?
async
support was added in nodejs v7.6
Given you're running nodejs v6.13.0 - that's why it fails
Solution: upgrade your nodejs on the target server or don't use async
.
The keywords async/await were introduced in ES2017.
You may need to transpile your ES2017 code into a syntax that your EC2 Node version understands. If your EC2 is not running Node v7.6 or greater ( node -v
), then async/await will not work out of the box.
Transpile your js with Babel or upgrade node to the latest LTS on your EC2 instance.
Check for . babelrc It must be missing
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.