AWS Lambda错误:无法加载gRPC二进制模块,因为它尚未为当前系统

时间:2017-12-26 13:54:18

标签: firebase aws-lambda glibc google-cloud-firestore grpc

我在使用无服务器框架的AWS Lambda功能部署时遇到问题。我使用@google-cloud-firestore npm包,需要grpc包。

函数执行抛出错误:

{
  "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)"
  ]
}

因此,据我所知,lambda需要使用目标node-v48-linux-x64-glibc

构建的grps

键入npm i -S grpc --target=6.4.0 --target_arch=x64 --target_platform=linux仅将node-v59-darwin-x64-unknown更改为node-v48-linux-x64-unknown

如何将unknown更改为glibc

任何帮助都会非常感激!

2 个答案:

答案 0 :(得分:6)

Fix

基本上,您需要指定grcp库的目标。 从该链接复制:

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

答案 1 :(得分:1)

通过在documentation for node-pre-gyp中找到--target_libc=glibc,我得到了类似于工作的内容。