NoKey
NoKey

Reputation: 403

node-v57-linux-x64/grpc_node.node missing

When following exactly these steps:

https://firebase.google.com/docs/admin/setup

And deploying to my server, I get this error:

2017-10-16 19:19:56 4199bf47fc2d ---> Starting app
2017-10-16 19:19:56 4199bf47fc2d Detected server.js file
2017-10-16 19:19:57 4199bf47fc2d module.js:529
2017-10-16 19:19:57 4199bf47fc2d     throw err;
2017-10-16 19:19:57 4199bf47fc2d     ^
2017-10-16 19:19:57 4199bf47fc2d 
2017-10-16 19:19:57 4199bf47fc2d Error: Cannot find module '/data/app/node_modules/firebase-admin/node_modules/grpc/src/node/extension_binary/node-v57-linux-x64/grpc_node.node'
2017-10-16 19:19:57 4199bf47fc2d     at Function.Module._resolveFilename (module.js:527:15)
2017-10-16 19:19:57 4199bf47fc2d     at Function.Module._load (module.js:476:23)
2017-10-16 19:19:57 4199bf47fc2d     at Module.require (module.js:568:17)
2017-10-16 19:19:57 4199bf47fc2d     at require (internal/module.js:11:18)
2017-10-16 19:19:57 4199bf47fc2d     at Object.<anonymous> (/data/app/node_modules/firebase-admin/node_modules/grpc/src/node/src/grpc_extension.js:30:15)
2017-10-16 19:19:57 4199bf47fc2d     at Module._compile (module.js:624:30)
2017-10-16 19:19:57 4199bf47fc2d     at Object.Module._extensions..js (module.js:635:10)
2017-10-16 19:19:57 4199bf47fc2d     at Module.load (module.js:545:32)
2017-10-16 19:19:57 4199bf47fc2d     at tryModuleLoad (module.js:508:12)
2017-10-16 19:19:57 4199bf47fc2d     at Function.Module._load (module.js:500:3)

It was installed in a new folder, newest npm and all, removed node_modules map reinstalled, npm install --unsafe-perm, npm rebuild etc. Nothing is working. Why isn't the module being installed?

Upvotes: 5

Views: 8437

Answers (3)

haminh
haminh

Reputation: 1

In my case, to resolve the problem I am using macOS:

Local run:

npm i -D

And run the below command to deploy production:

npm i --production --unsafe-perm --target=8.10.0 --target_platform=linux --target_arch=x64 --target_libc=glibc --update-binary

you can run the above command by creating a file, for example, sls-deploy.sh

#!/usr/bin/env bash

set -x
set -e

WORK_DIR=./lambda-tmp
COMPILED_DIR=./compiled
BIN_DIR=`npm bin`

rm -rf $WORK_DIR
rm -rf $COMPILED_DIR
${BIN_DIR}/tsc
cp -r $COMPILED_DIR $WORK_DIR
cp ./serverless.yml $WORK_DIR
cp ./package.json $WORK_DIR
.....
cp ./firebase-api-key.json $WORK_DIR
cp ./staging-firebase-api-key.json $WORK_DIR
cd $WORK_DIR
npm i --production --unsafe-perm
npx serverless deploy --stage $ENV_NAME --force

then run

bash -x sls-deploy.sh

Upvotes: 0

AndreasPizsa
AndreasPizsa

Reputation: 1746

This helped in my case:

npm rebuild --target=8.1.0 --target_platform=linux --target_arch=x64 --target_libc=glibc --update-binary

It downloads the required binary to your node_modules/grpc directory.

I run macOS X on my dev machine and I’m deploying to AWS Lambda; this keeps both runtime versions installed, which means I can develop and test locally and then deploy to Lambda.

Upvotes: 14

Christopher Fitzner
Christopher Fitzner

Reputation: 84

I just ran into the same issue. For us the problem was that we're installing the node modules on a mac and the install of firebase-admin is putting a platform specific file in for the binary.

After running the install and checking this directory I see this:

$ ls node_modules/firebase-admin/node_modules/grpc/src/node/extension_binary/
node-v48-darwin-x64

But the environment that is running the lamba is looking for:

 node-v48-linux-x64

An easy solution is to run the npm install in the same environment that the lambda is running in using docker. In our case I found that the lambci project has prebuilt docker containers for this exact use case. Here I've added an npm script line to handle the build:

  "scripts": {
      "package": "rm -rf node_modules && docker run -v $PWD:/var/task -w /var/task lambci/lambda:build-nodejs6.10 npm install"
  },

Upvotes: 4

Related Questions