serverless / serverless-google-cloudfunctions

Serverless Google Cloud Functions Plugin – Adds Google Cloud Functions support to the Serverless Framework
https://www.serverless.com
MIT License
271 stars 127 forks source link

Question - On `sls deploy` - Is it possible to have multiple functions per serverless yml file? #221

Open josoroma-zz opened 4 years ago

josoroma-zz commented 4 years ago

Error: Deployment failed: RESOURCE_ERROR

image

serverless.yml

image

index.js

image

service: josoroma-gcloud-stack # Don't use the word "google" in here

provider:
  name: google
  runtime: nodejs12
  stage: dev
  region: us-east1
  # Google provider settings
  project: josoroma-gcloud-stack # Google account project id
  credentials: ~/.gcloud/josoroma-gcloud-stack-a969c850ed30.json

plugins:
  - serverless-google-cloudfunctions

package:
  exclude:
    - node_modules/**
    - .gitignore
    - .git/**

functions:
  graphql:
    handler: handlerGraphql
    events:
      - http: path

  test:
    handler: handlerTest
    events:
      - http: path

src/graphql.js

image

src/tes.js

image

Thanks!

CorentinDoue commented 3 years ago

Your first screenshot tells you that Node doesn't recognize the export keyword. Indeed, Node < 13 doesn't support ECMAScript modules.

So it's not a serverless-google-cloudfunctions problem and this issue could be closed

Solution 1:

Use require

Solution 2:

Transpile your code from ESNext to a node12 target before deploying it. You can use https://github.com/serverless-heaven/serverless-webpack or https://github.com/floydspace/serverless-esbuild for example

christopher-caldwell commented 1 year ago

@CorentinDoue Do you have an example of setting up GCP with ESBuild? I keep getting:

Error: Failed to require one of the files /syncs/.esbuild/.build/index.js, /syncs/.esbuild/.build/function.js

I am trying to do this same pattern of having an index.ts file with these exports. ESBuild does not put the file into the build folder.

On a side note, does anyone know why Google enforces files to be like this? AWS' implementation is far simpler. Is this a limitation brought by GCP or this lib?