首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无服务器异步函数错误

无服务器异步函数错误
EN

Stack Overflow用户
提问于 2018-06-07 15:58:35
回答 2查看 744关注 0票数 0

我正在使用serverless来运行lambda函数。

尝试执行sls invoke local --function myFunction时面临的问题

代码语言:javascript
复制
exports.myFunction = async (event) => {
                         ^
SyntaxError: Unexpected token (
    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)

无服务器配置如下所示。

serverless.yaml

代码语言:javascript
复制
service: myService

provider:
  name: aws
  runtime: nodejs8.10
  stage: ${opt:stage, 'dev'}
  region: eu-west-1

  environment:
    CUSTOM_ENV: ${opt:stage, 'dev'}


functions:
  myFunction:
    handler: index.myFunction
    events:
      - http: 
          cors: true
          path: /{proxy+}
          method: POST
plugins:
  - serverless-offline
  - serverless-webpack

webpack.config.js

代码语言:javascript
复制
const slsw = require("serverless-webpack");
const nodeExternals = require("webpack-node-externals");
const path = require('path');

module.exports = {
  entry: slsw.lib.entries,
  target: "node",
  // Generate sourcemaps for proper error messages
  devtool: 'source-map',

  mode: slsw.lib.webpack.isLocal ? "development" : "production",

  optimization: {
    // We no not want to minimize our code.
    minimize: false
  },
  performance: {
    // Turn off size warnings for entry points
    hints: false
  },


};

在运行命令sls offline start

在命中函数路由之前,一切似乎都很正常。

EN

回答 2

Stack Overflow用户

发布于 2018-06-11 10:16:23

sls invoke local 通过模拟AWS Lambda环境在本地运行您的代码。因此,请确保您在开发机器上安装了node 8和更高版本,以获得异步等待本机支持。在本地运行node --version以检查您的节点开发版本。

票数 8
EN

Stack Overflow用户

发布于 2020-10-13 10:49:44

请确保您在estlintrc.js上使用的是ECMA script 8。

然后它就可以正常工作了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50735838

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档