0

I have a local Docker developer environment to build a Sails.js application. This is what my Dockerfile looks like:

FROM node:8.12
LABEL Name=us.gcr.io/my-project/my-app Version=1.0.0

# Container configuration
RUN npm install -g sails@1.0.2 grunt@1.0.3 nodemon@1.18.4
WORKDIR /usr/src/app
COPY ./server/package.json ./package.json
RUN npm install
VOLUME /usr/src/app
EXPOSE 1337

This is what my docker-compose.yml file looks like:

version: '3.4'

services:
  server:
    image: us.gcr.io/my-project/my-app:latest
    build: .
    environment:
      NODE_ENV: development
      IS_DEV_MACHINE: "yes"
    ports:
      - 1338:1337 # HOST_PORT is 1339 to avoid conflicts with other Sails.js apps running on host
    volumes:
      - ./server:/usr/src/app
    entrypoint: nodemon

  mongodb:
    image: mongo:4
    ports:
      - 27018:27017 # HOST_PORT is 27018 to avoid conflicts with other MongoDB databases running on host
    volumes:
      - ../database:/data/db

Normally, everything works fine however, I recently imported and initialised the @google-cloud/logging NPM package in my application and now, when I run docker-compose up, I get the following error:

server_1   | error: Bootstrap encountered an error: (see below)
server_1   | error: Failed to lift app: { Error: Failed to load gRPC binary module because it was not installed for the current system
server_1   | Expected directory: node-v57-linux-x64-musl
server_1   | Found: [node-v57-darwin-x64-unknown]
server_1   | This problem can often be fixed by running "npm rebuild" on the current system
server_1   | Original error: Cannot find module '/usr/src/app/node_modules/grpc/src/node/extension_binary/node-v57-linux-x64-musl/grpc_node.node'
server_1   |     at Object.<anonymous> (/usr/src/app/node_modules/grpc/src/grpc_extension.js:53:17)
server_1   |     at Module._compile (module.js:653:30)
server_1   |     at Object.Module._extensions..js (module.js:664:10)
server_1   |     at Module.load (module.js:566:32)
server_1   |     at tryModuleLoad (module.js:506:12)
server_1   |     at Function.Module._load (module.js:498:3)
server_1   |     at Module.require (module.js:597:17)
server_1   |     at require (internal/module.js:11:18)
server_1   |     at Object.<anonymous> (/usr/src/app/node_modules/grpc/src/client_interceptors.js:145:12)
server_1   |     at Module._compile (module.js:653:30)
server_1   |     at Object.Module._extensions..js (module.js:664:10)
server_1   |     at Module.load (module.js:566:32)
server_1   |     at tryModuleLoad (module.js:506:12)
server_1   |     at Function.Module._load (module.js:498:3)
server_1   |     at Module.require (module.js:597:17)
server_1   |     at require (internal/module.js:11:18) code: 'MODULE_NOT_FOUND' }
mongodb_1  | 2018-10-09T09:27:52.521+0000 I NETWORK  [conn4] end connection 172.19.0.2:48730 (0 connections now open)

In the error above, "Bootstrap" is the bootstrap.js file in my Sails.js project that initialises @google-cloud/logging. This is how I am initialising the logger in bootstrap.js:

// Globally required packages
const { Logging } = require('@google-cloud/logging');
const logging = new Logging({ projectId: 'my-project' });
const logger = logging.log('test');

I just can't seem to figure out why this error is occurring. I even tried changing my base Docker image to the official Google App Engine Docker image (gcr.io/google-appengine/nodejs) and that did not help either. i can't find any solutions to this problem anywhere. Appreciate any help.

JackH
  • 4,613
  • 4
  • 36
  • 61
  • According to the error message, you can run "npm rebuild" on the current system to see if that helps. For similar issue of "Error: Failed to load gRPC binary module...", please visit [this link](https://stackoverflow.com/questions/49758008/nodejs-error-failed-to-load-grpc-binary-module-because-it-was-not-installed-fo) and [this](https://github.com/grpc/grpc/issues/15431) and try their suggestions. – mehdi sharifi Oct 11 '18 at 23:13

3 Answers3

2

By any chance did you do a npm install on your local Mac (darwin) environment when it should have been done in the container (linux)? The grpc binary is for the wrong OS thus the error. This often happens with a local Mac running a linux Docker container.

Expected directory: node-v57-linux-x64-musl Found: [node-v57-darwin-x64-unknown]

The solution would be to rm -fr node_modules and do npm install in the container.

DeeZone
  • 770
  • 7
  • 16
1

Rebuild the app by the following command.

npm rebuild --target=8.1.0 --target_platform=linux --target_arch=x64 --target_libc=musl
Abu Sufian
  • 11
  • 2
0

It looks like the project is having difficulty finding dependencies such as the gRPC binary module (repaired with npm install grpc) or perhaps where they are currently located - more info here

johnabrams7
  • 399
  • 2
  • 10