Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/404.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Azure函数在语法有效时抱怨JS语法错误_Javascript_Azure_Ecmascript 6_Azure Functions - Fatal编程技术网

Javascript Azure函数在语法有效时抱怨JS语法错误

Javascript Azure函数在语法有效时抱怨JS语法错误,javascript,azure,ecmascript-6,azure-functions,Javascript,Azure,Ecmascript 6,Azure Functions,我在JS中定义了一个Azure函数 module.exports = async function (context, req) { if (req.query.name || (req.body && req.body.name)) { // generate mock result const mockChecker = new mockCheckBuild(); const result = await mockCh

我在JS中定义了一个Azure函数

module.exports = async function (context, req) {
    if (req.query.name || (req.body && req.body.name)) {

        // generate mock result
        const mockChecker = new mockCheckBuild();
        const result = await mockChecker.runAsync();

        context.res = {
            body: result
        };
    }
    else {
        context.res = {
            status: 400,
            body: "Please pass a name on the query string or in the request body"
        };
    }
    context.done();
};

function mockCheckBuild() {
   this.statuses = ['Failed', 'Complete'];

   this.branchId = 808;

   this.buildNumbers = ['0.1.1.1023', '0.1.1.1024', '0.1.1.1025'];

   this.runAsync = async function() {
      return new Promise(resolve => 
        setTimeout(() =>
            resolve({
                branchId: this.branchId,
                latestBuild: this.statuses.randomElement(),
                buildStatus: this.buildNumbers.randomElement()
            })
        , 2000)
      );
   };

   return this;
}

Array.prototype.randomElement = function()
{
    const index = Math.floor(Math.random() * this.length);
    return this[index];
};
我已经运行了许多语法验证器来验证它是正确的JavaScript。我还将注意到,Azure语法高亮显示了诸如
async
const
之类的词

然而,当我运行它时,我得到了

执行函数时出现异常:Functions.CheckLatestBuild->One 发生了一个或多个错误。-> D:\home\site\wwwroot\CheckLatestBuild\index.js:1\n(函数 (导出,require,module,_文件名,_目录名){module.exports= 异步函数(上下文,请求){\n
^^^^^^^^\n\n语法错误:出现意外的令牌函数\n createScript(vm.js:56:10)\n位于Object.runInThisContext (vm.js:97:10)\n位于模块_


知道为什么吗?或者关于如何更好地调查的建议吗?

Azure Functions v1运行Node 6.x,它不支持异步。如果您改为尝试Functions v2 Preview,您可以运行Node 8.x(很快将运行10.x),异步将起作用