Search code examples
firebaseaws-lambdaglibcgoogle-cloud-firestoregrpc

AWS Lambda Error: Failed to load gRPC binary module because it was not installed for the current system


I have problem with AWS Lambda function deployment with Serverless Framework. I use @google-cloud-firestore npm package which requires grpc package.

Function execution throws error:

{
  "errorMessage": "Failed to load gRPC binary module because it was not installed for the current system\nExpected directory: node-v48-linux-x64-glibc\nFound: [node-v59-darwin-x64-unknown]\nThis problem can often be fixed by running \"npm rebuild\" on the current system\nOriginal error: Cannot find module '/var/task/node_modules/grpc/src/node/extension_binary/node-v48-linux-x64-glibc/grpc_node.node'",
  "errorType": "Error",
  "stackTrace": [
    "Found: [node-v48-linux-x64-unknown]",
    "This problem can often be fixed by running \"npm rebuild\" on the current system",
    "Original error: Cannot find module '/var/task/node_modules/grpc/src/node/extension_binary/node-v48-linux-x64-glibc/grpc_node.node'",
    "Object.<anonymous> (/var/task/node_modules/grpc/src/grpc_extension.js:44:17)",
    "Module._compile (module.js:570:32)",
    "Object.Module._extensions..js (module.js:579:10)",
    "Module.load (module.js:487:32)",
    "tryModuleLoad (module.js:446:12)",
    "Function.Module._load (module.js:438:3)",
    "Module.require (module.js:497:17)",
    "require (internal/module.js:20:19)",
    "Object.<anonymous> (/var/task/node_modules/grpc/src/client.js:38:12)",
    "Module._compile (module.js:570:32)",
    "Object.Module._extensions..js (module.js:579:10)",
    "Module.load (module.js:487:32)",
    "tryModuleLoad (module.js:446:12)",
    "Function.Module._load (module.js:438:3)",
    "Module.require (module.js:497:17)",
    "require (internal/module.js:20:19)"
  ]
}

So, as I understood, lambda requires grps built with target node-v48-linux-x64-glibc

Typing npm i -S grpc --target=6.4.0 --target_arch=x64 --target_platform=linux has only changed node-v59-darwin-x64-unknown to node-v48-linux-x64-unknown.

How can I change unknown to glibc?

Any help would be really appreciated!


Solution

  • Fix

    Basically, you need to specify the target of the grcp library. Copied from that link:

    {
      "main": "index.js",
      "scripts": {
      "postinstall": "npm rebuild grpc --target=6.1.0 --target_arch=x64 --target_platform=linux --target_libc=glibc"
      }
    }