5

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?

NoKey
  • 129
  • 11
  • 32

3 Answers3

14

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.

AndreasPizsa
  • 1,736
  • 19
  • 26
4

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"
  },
  • I was really getting frustated >.< I dislike NPM and Git because everything needs to be done in a freaking terminal without a UI. I fixed the problem finally after finding the file somewhere on a random google docs site. I added that file and updated. I guess your answer will work as well. – NoKey Oct 19 '17 at 00:18
  • It didn't work for me! I still get `Cannot find module '/tmp/fbfn_284TLWMJRfpLbZI/node_modules/firebase-admin/node_modules/grpc/src/node/extension_binary/node-v57-linux-x64/grpc_node.node'` If someone is mounting the docker volumes to container instead of installing docker in container like: `docker run -it -v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker ubuntu:latest bash` then they have to give the host file path in the place of `$PWD` because the docker is running from the host machine and not the container. – Phani Oct 24 '17 at 12:05
  • @Phani I'm not sure I'm following. Can you further describe your setup? It sounds like you're in a docker in docker situation. Are you saying this modification worked for you in this situation? – Christopher Fitzner Mar 15 '18 at 07:50
  • Yes @ChristopherFitzner I've a docker container running my DEV environment. Hence I've had to give the absolute path of HOST machine in place of $PWD to make this work for me. – Phani Mar 15 '18 at 10:32
0

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

haminh
  • 1