gpt4 book ai didi

node.js - 在Docker容器中运行Sails.js应用程序时出现“Failed to load gRPC binary module”错误

转载 作者:行者123 更新时间:2023-12-02 20:46:25 25 4
gpt4 key购买 nike

我有一个本地Docker开发人员环境来构建Sails.js应用程序。这是我的Dockerfile的样子:

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

这是我的docker-compose.yml文件的样子:
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

通常,一切正常,但是,我最近在应用程序中导入并初始化了 @google-cloud/logging NPM软件包,现在,当我运行 docker-compose up时,出现以下错误:
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)

在上面的错误中,“Bootstrap”是我的Sails.js项目中的bootstrap.js文件,用于初始化@ google-cloud / logging。这就是我在bootstrap.js中初始化记录器的方式:
// Globally required packages
const { Logging } = require('@google-cloud/logging');
const logging = new Logging({ projectId: 'my-project' });
const logger = logging.log('test');

我只是似乎无法弄清楚为什么会发生此错误。我什至尝试将基本的Docker镜像更改为正式的Google App Engine Docker镜像(gcr.io/google-appengine/nodejs),但这也无济于事。我在任何地方都找不到解决此问题的方法。感谢任何帮助。

最佳答案

您是否有机会在应该在容器(npm install)中完成的本地Mac(darwin)环境中执行了linux? grpc二进制文件用于错误的OS,因此错误。这通常是在运行Linux Docker容器的本地Mac上发生的。

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

解决方案是在容器中添加rm -fr node_modules并执行npm install

关于node.js - 在Docker容器中运行Sails.js应用程序时出现“Failed to load gRPC binary module”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52721947/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com