“Failed to load gRPC binary module” error when running a Sails.js application inside a Docker container

流过昼夜 提交于 2019-12-13 02:58:26

问题


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.


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/52721947/failed-to-load-grpc-binary-module-error-when-running-a-sails-js-application-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!