Serverless Offline: The "path" argument must be of type string. Received undefined

1.4k views Asked by At

Not sure why this started happening but I have a very simple serverless app that was working, but now when I run sls offline start I get the error above. I have found the culprit and it is the events inside the functions.

Here is the serverless.yml file:

service: hello-world-offline

provider:
  name: aws
  runtime: nodejs12.x
  region: eu-east-1
  stage: dev

plugins:
  - serverless-offline

functions:
  hello-world:
    handler: handler.handle # required, handler set in AWS Lambda
    events:
      - http:
          path: hello-world
          method: get
          cors: true

Here is the handler.js file:

module.exports.handle = async (event, ctx, cb) => {
  cb(null, {
    statusCode: 200,
    body: JSON.stringify({ message: "hello world" })
  })
}

If I get rid of the events in the function hello-world everything works just fine with sls offline start except for the fact I can't actually hit the endpoint locally of course. I've tried making it a hard string by adding quotes but that did nothing.

EDIT: Turns out this happens when using yarn workspaces. If I put this in a packages/my-serverless-app structure and cd into the folder to run the sls offline start command this happens. If I remove it from the structure it works just fine.

1

There are 1 answers

0
HawkEye On

Change

events:
      - http:
          path: hello-world
          method: get
          cors: true

TO

events:
      - httpApi:
          path: hello-world
          method: get

And this should work!