简体   繁体   English

JavaScript代码在AWS EC2实例上失败

[英]JavaScript code failing on AWS EC2 instance

In my JavaScript program, I have: 在我的JavaScript程序中,我有:

const myFunction = async function (input) {
 // do stuff
}

It runs fine on Windows 10. But same code gives error on AWS EC2 instance: 它可以在Windows 10上正常运行。但是相同的代码在AWS EC2实例上产生错误:

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 在nodejs v7.6中添加了async支持

Given you're running nodejs v6.13.0 - that's why it fails 鉴于您正在运行nodejs v6.13.0-这就是为什么它失败

Solution: upgrade your nodejs on the target server or don't use async . 解决方案:在目标服务器上升级nodejs或不使用async

The keywords async/await were introduced in ES2017. 关键字async / await在ES2017中引入。

You may need to transpile your ES2017 code into a syntax that your EC2 Node version understands. 您可能需要将ES2017代码转换为EC2节点版本可以理解的语法。 If your EC2 is not running Node v7.6 or greater ( node -v ), then async/await will not work out of the box. 如果您的EC2没有运行Node v7.6或更高版本( node -v ),那么async / await将无法立即使用。

Transpile your js with Babel or upgrade node to the latest LTS on your EC2 instance. 使用Babel转换js或将节点升级到EC2实例上的最新LTS

Check for . 检查 。 babelrc It must be missing babelrc必须丢失

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM