環境/ライブラリ
- AWS Lambda(Node.js 8.10)
- @google-cloud/language
事象
AWS Lambda(Node.js)上の関数で、Google Cloud Natural Language APIを呼び出すとエラー"Failed to load gRPC"が発生する。
エラーログ例
Error: Failed to load gRPC binary module because it was not installed for the current system
Expected directory: node-v57-linux-x64-glibc
Found: [node-v57-darwin-x64-unknown]
This problem can often be fixed by running "npm rebuild" on the current system
Original error: Cannot find module '/opt/nodejs/node_modules/grpc/src/node/extension_binary/node-v57-linux-x64-glibc/grpc_node.node'
at Object.<anonymous> (/opt/nodejs/node_modules/grpc/src/grpc_extension.js:53:17)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/opt/nodejs/node_modules/grpc/src/client_interceptors.js:144:12)
at Module._compile (module.js:652:30) code: 'MODULE_NOT_FOUND
対応方法
以下のコマンドでリビルドする。targetはNode.jsのバージョンに合わせる
npm rebuild grpc —target=8.1.0 --target_arch=x64 --target_platform=linux --target_libc=glibc
感想
こういうエラーが起きると、Pythonにすれば良かったと思う(逆もまた然り)