简体   繁体   English

部署到Heroku的NodeJS应用程序不支持异步功能

[英]Async function not supported in NodeJS app deployed to Heroku

I'm trying to implement asynchronous functionality in one of my routes in a NodeJS app. 我正在尝试在NodeJS应用程序的其中一条路由中实现异步功能。 It works when I run it on localhost but when deployed to heroku, an error unexpected token ( is thrown in the first line of the following code: 当我在localhost上运行它时,它起作用了,但是当部署到heroku时,错误的unexpected token (在以下代码的第一行中引发:

router.post('/post', async(req,res) => {
    const data = await getData();
    //do stuff

})

I'm a little confused as to why this works in one environment and not the other. 我对为什么它在一个环境而不在另一个环境中起作用感到有些困惑。 Are there heroku configurations I'm missing? 我是否缺少heroku配置? Do I need to explicitly add support for ES2016/2017 in Heroku? 我是否需要在Heroku中显式添加对ES2016 / 2017的支持?

Heroku defaults to the latest Long Term Support version of Node (which, as of writing, is v6.11.1) if you don't set a specific version. 如果您未设置特定版本,则Heroku默认为Node的最新长期支持版本(截至撰写时为v6.11.1)。

async/await has been available in Node since v7.6, so you'll need to explicitly specify at least that version in your package.json , as documented here: https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version 从v7.6开始, async/await已在Node中可用,因此您需要在package.json显式指定至少该版本,如此处所述: https : //devcenter.heroku.com/articles/nodejs-support #指定-A-节点JS-版本

you can refer this link 你可以参考这个链接

Es6_hrku Es6_hrku

You need to convert your ES6 to ES5 in order to make it happen on heroku. 您需要将ES6转换为ES5,以使其在heroku上发生。 Changes required in package.json. package.json中需要进行的更改。

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

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