Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
josoroma-zz opened this issue Jun 24, 2020 · 2 comments

Comments

@josoroma-zz
Copy link

josoroma-zz commented Jun 24, 2020

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
Copy link
Contributor

CorentinDoue commented Apr 3, 2021

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
Copy link

christopher-caldwell commented Oct 26, 2022

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment