GoogleCloudPlatform / functions-framework-nodejs

FaaS (Function as a service) framework for writing portable Node.js functions
Apache License 2.0
1.31k stars 160 forks source link

Build error when deploying from gcloud cli with local file dependencies #591

Open immber opened 9 months ago

immber commented 9 months ago

Deploying from local source with gcloud functions deploy seems unable to include local file dependencies.

When setting --set-build-env-vars GOOGLE_VENDOR_NPM_DEPENDENCIES=true and package.json is referencing something like "app-common": "file:./localpath" builds fail and throw the following build error:

"Step #2 - "build": panic: runtime error: invalid memory address or nil pointer dereference"

Was expecting this should work:

gcloud functions deploy my-function \
    --entry-point=create \
    --trigger-http \
    --set-build-env-vars GOOGLE_VENDOR_NPM_DEPENDENCIES=true 

But I was able to work around by building a docker image locally and manually pushing:

pack build \
  --builder gcr.io/buildpacks/builder:v1 \
  --env GOOGLE_FUNCTION_SIGNATURE_TYPE=http \
  --env GOOGLE_FUNCTION_TARGET=create \
  --env GOOGLE_VENDOR_NPM_DEPENDENCIES=true \
  my-function

If I try the gcloud functions deploy command minus the build env var, it pushes an image to the cloud function that is missing dependencies. It would be great if this could deploy from local source in one step and have it correctly include dependencies, instead of manually having to build a docker image and push.

kenneth-rosario commented 9 months ago

Hey immber can you share a small reproduction that is similar to your setup.

immber commented 9 months ago

@kenneth-rosario , I pushed up a little example here: https://github.com/immber/gcf-build-err

I've been following the docs at: https://cloud.google.com/functions/docs/writing/specifying-dependencies-nodejs#build_your_function_with_vendored_dependencies

The example is just exporting a string to reproduce the error, but my actual use case is that I'm including a /dist folder that is built by a nested dependency which I'm including at root inside my local source.

I'd love to be able to deploy directly with glcoud function deploy but instead I'm having to build the docker container manually with pack then push that to artifact registry, and then deploy a new revision from CloudRun.

kenneth-rosario commented 9 months ago

@immber Thanks for the reproduction. Will try this out!