Node Upgrade AWS Lambda: Failed to load gRPC binary module,因



我试图将我的lambda函数的nodeJS版本从v12升级到v16。这些功能已经通过无服务器部署,应用程序包含在docker映像中。

我的函数正在使用GRPC库,当我在升级后运行该函数时,弹出以下错误:

{
"errorType": "Runtime.ImportModuleError",
"errorMessage": "Error: Failed to load gRPC binary module because it was not installed for the current systemnExpected directory: node-v83-linux-x64-glibcnFound: [node-v72-linux-x64-glibc]nThis problem can often be fixed by running "npm rebuild" on the current systemnOriginal error: Cannot find module '/var/task/node_modules/grpc/src/node/extension_binary/node-v83-linux-x64-glibc/grpc_node.node'nRequire stack:n- /var/task/node_modules/grpc/src/grpc_extension.jsn- /var/task/node_modules/grpc/src/client_interceptors.jsn- /var/task/node_modules/grpc/src/client.jsn- /var/task/node_modules/grpc/index.jsn- /var/task/src/index.jsn- /var/runtime/UserFunction.jsn- /var/runtime/Runtime.jsn- /var/runtime/index.js",
"stack": [
"Runtime.ImportModuleError: Error: Failed to load gRPC binary module because it was not installed for the current system",
"Expected directory: node-v83-linux-x64-glibc",
"Found: [node-v72-linux-x64-glibc]",
"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-v83-linux-x64-glibc/grpc_node.node'",
"Require stack:",
"- /var/task/node_modules/grpc/src/grpc_extension.js",
"- /var/task/node_modules/grpc/src/client_interceptors.js",
"- /var/task/node_modules/grpc/src/client.js",
"- /var/task/node_modules/grpc/index.js",
"- /var/task/src/index.js",
"- /var/runtime/UserFunction.js",
"- /var/runtime/Runtime.js",
"- /var/runtime/index.js",
"    at _loadUserApp (/var/runtime/UserFunction.js:225:13)",
"    at Object.module.exports.load (/var/runtime/UserFunction.js:300:17)",
"    at Object.<anonymous> (/var/runtime/index.js:43:34)",
"    at Module._compile (internal/modules/cjs/loader.js:1085:14)",
"    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)",
"    at Module.load (internal/modules/cjs/loader.js:950:32)",
"    at Function.Module._load (internal/modules/cjs/loader.js:790:12)",
"    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)",
"    at internal/main/run_main_module.js:17:47"
]
}

我正在更新我的serverless

的运行时间
runtime: nodejs12.x   // changing it to 14 or 16 here 

并同时更改Docker

中的版本
FROM node:12 as builder        # changed to 14 or 16 as per serverless runtime
# ensure installation
RUN node -v; npm -v
#### Few COPY Command on package.json ###
RUN yarn install --frozen-lockfile

FROM builder as base

当我通过Lambda中的运行时设置更改版本时也会遇到该错误。
AWS Lambda Runtime更改屏幕

尝试了以下几个步骤:

  1. 尝试通过serverless和Dockerfile升级版本。
  2. 从AWS更改运行时设置。

该错误表明grpc包是使用不同版本的Node安装的,而不是正在加载它的Node。您可以通过从头开始重新构建docker映像来解决这个问题。但是,grpc包已被弃用,并且不能在任何大于14的Node版本上工作。更换包为@grpc/grpc-js

最新更新