代码之家  ›  专栏  ›  技术社区  ›  Talha Talip Açıkgöz

Firebase异步函数语法错误

  •  4
  • Talha Talip Açıkgöz  · 技术社区  · 9 年前

    我有一个节点。js v8.3.0,并在我的软件包中。json:

      "engines": {
        "node": ">=8.3.0"
      }
    

    以及我的等待/异步测试代码:

    async function x() {
        return "test";
    }
    
    exports.asyncTest = functions.https.onRequest((request, response) => async function() {
        response.end(await x());
    });
    

    预期输出: test
    观察到的输出:

    Is there a syntax error in your code?
    Detailed stack trace: /user_code/index.js:12
    async function x() {
          ^^^^^^^^
    SyntaxError: Unexpected token function
        at createScript (vm.js:56:10)
        at Object.runInThisContext (vm.js:97:10)
        at Module._compile (module.js:542:28)
        at Object.Module._extensions..js (module.js:579:10)
        at Module.load (module.js:487:32)
        at tryModuleLoad (module.js:446:12)
        at Function.Module._load (module.js:438:3)
        at Module.require (module.js:497:17)
        at require (internal/module.js:20:19)
        at getUserFunction (/var/tmp/worker/worker.js:372:24)
    
    1 回复  |  直到 9 年前
        1
  •  10
  •   Michael Bleigh    9 年前

    同时,您需要使用像Babel或TypeScript这样的transpiler来利用async/await。

    推荐文章