Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCF Node10 deploy failed: "Function failed on loading user code. Error message: Provided code is not a loadable module."

After making some adjustments (a rather big PR), which basically adds Google Cloud Storage connection to this function, deployment starts to fail. Unfortunately, the error message is pretty unclear and therefore doesn't provide me in much hint. Locally and in tests things run fine, so I'm a bit lost right now which direction to search. Logs don't provide insights either.

Can't really easily share the changes in the PR unfortunately. Worst case I'll revert and go piece by piece from there, but that's a tedious process.

The service account that is used in the deployment got access to the used bucket (with write), but I also don't think this error hints to permissions else I hope the error message would be more insightful.

Command used:

gcloud beta functions deploy eventStreamPostEvent --runtime nodejs10 --memory 128MB --trigger-http --source ./dist --service-account $DEPLOY_SERVICE_ACCOUNT --verbosity debug

Deploying function (may take a while - up to 2 minutes)...
..............................failed.
DEBUG: (gcloud.beta.functions.deploy) OperationError: code=3, message=Function failed on loading user code. Error message: Provided code is not a loadable module.
Could not load the function, shutting down.
Traceback (most recent call last):
  File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/calliope/cli.py", line 985, in Execute
    resources = calliope_command.Run(cli=self, args=args)
  File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/calliope/backend.py", line 795, in Run
    resources = command_instance.Run(args)
  File "/usr/lib/google-cloud-sdk/lib/surface/functions/deploy.py", line 231, in Run
    enable_vpc_connector=True)
  File "/usr/lib/google-cloud-sdk/lib/surface/functions/deploy.py", line 175, in _Run
    return api_util.PatchFunction(function, updated_fields)
  File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/api_lib/functions/util.py", line 300, in CatchHTTPErrorRaiseHTTPExceptionFn
    return func(*args, **kwargs)
  File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/api_lib/functions/util.py", line 356, in PatchFunction
    operations.Wait(op, messages, client, _DEPLOY_WAIT_NOTICE)
  File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/api_lib/functions/operations.py", line 126, in Wait
    _WaitForOperation(client, request, notice)
  File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/api_lib/functions/operations.py", line 101, in _WaitForOperation
    sleep_ms=SLEEP_MS)
  File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/core/util/retry.py", line 219, in RetryOnResult
    result = func(*args, **kwargs)
  File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/api_lib/functions/operations.py", line 65, in _GetOperationStatus
    raise exceptions.FunctionsError(OperationErrorToString(op.error))
FunctionsError: OperationError: code=3, message=Function failed on loading user code. Error message: Provided code is not a loadable module.
Could not load the function, shutting down.

ERROR: (gcloud.beta.functions.deploy) OperationError: code=3, message=Function failed on loading user code. Error message: Provided code is not a loadable module.
Could not load the function, shutting down.

I hope anyone knows what is causing this error.

Stackdriver logs show me nothing more than:

 protoPayload: {
  @type:  "type.googleapis.com/google.cloud.audit.AuditLog"   
  authenticationInfo: {…}   
  methodName:  "google.cloud.functions.v1.CloudFunctionsService.UpdateFunction"   
  requestMetadata: {
   destinationAttributes: {…}    
   requestAttributes: {…}    
  }
  resourceName:  "projects/<projectName>/locations/europe-west1/functions/eventStreamPostEvent"   
  serviceName:  "cloudfunctions.googleapis.com"   
  status: {
   code:  3    
   message:  "INVALID_ARGUMENT"    
  }
 }
like image 918
stefandoorn Avatar asked May 01 '19 13:05

stefandoorn


1 Answers

I had the same issue and seems the message comes from here.

When you have multiple .js files with some subfolders in the root folder of your function, by default without any specification you need to name the entry module as index.js or function.js.

I found that by deploying the function using node8. The error messages should be clearer...

like image 154
BMWCMW Avatar answered Oct 13 '22 05:10

BMWCMW