Google-cloud-node: Using @google-cloud/datastore in Docker project creates cannot find error for grpc

Created on 1 Oct 2017  路  5Comments  路  Source: googleapis/google-cloud-node

Environment details

  • OS: Windows 10
  • Node.js version: 6.11.2
  • npm version: 3.10.10
  • google-cloud-node version: 1.1.0

Steps to reproduce

_Note I am not using grpc in the project_

  1. install @ google-cloud/datastore in Docker app
    I am trying this on base version of: https://github.com/kriasoft/nodejs-api-starter
  2. start server
  3. Get the following error
api_1    | Error: Cannot find module '/usr/src/app/node_modules/@google-cloud/datastore/node_modules/grpc/src/node/extension_binary/node-v57-linux-x64/grpc_node.node'
api_1    |     at Function.Module._resolveFilename (module.js:527:15)
api_1    |     at Function.Module._load (module.js:476:23)
api_1    |     at Module.require (module.js:568:17)
api_1    |     at require (internal/module.js:11:18)
api_1    |     at Object.<anonymous> (/usr/src/app/node_modules/@google-cloud/datastore/node_modules/grpc/src/node/src/grpc_extension.js:30:15)
api_1    |     at Module._compile (module.js:624:30)
api_1    |     at Object.Module._extensions..js (module.js:635:10)
api_1    |     at Module.load (module.js:545:32)
api_1    |     at tryModuleLoad (module.js:508:12)
api_1    |     at Function.Module._load (module.js:500:3)
api_1    | module.js:529
api_1    |     throw err;
api_1    |     ^

If I try and install this into the project with yarn I get an error and can't even install it

$ yarn add @google-cloud/datastore
yarn add v0.27.5
[1/4] Resolving packages...
[2/4] Fetching packages...
warning [email protected]: The platform "win32" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning "[email protected]" has incorrect peer dependency "graphql@^0.5.0 || ^0.6.0 || ^0.7.0 || ^0.8.0-b || ^0.9.0 || ^0.10.0".
error An unexpected error occurred: "EPERM: operation not permitted, lstat 'C:\\Projects\\myiworlds\\myiworlds-backend\\node_modules\\grpc\\package.json'".
info If you think this is a bug, please open a bug report with the information provided in "C:\\Projects\\myiworlds\\myiworlds-backend\\yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

Trying to install google-cloud does the same

$ yarn add google-cloud
yarn add v0.27.5
[1/4] Resolving packages...
[2/4] Fetching packages...
warning [email protected]: The platform "win32" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning "[email protected]" has incorrect peer dependency "graphql@^0.5.0 || ^0.6.0 || ^0.7.0 || ^0.8.0-b || ^0.9.0 || ^0.10.0".
error An unexpected error occurred: "EPERM: operation not permitted, lstat 'C:\\Projects\\myiworlds\\myiworlds-backend\\node_modules\\grpc\\package.json'".
info If you think this is a bug, please open a bug report with the information provided in "C:\\Projects\\myiworlds\\myiworlds-backend\\yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

I have this working fine with another application that isn't using Docker which is leading me to believe something with Docker is likely the issue.

2017-10-01_10-28-46

datastore

Most helpful comment

@DaveyEdwards you can try to solve it by adding libc6-compat to Dockerfile and Dockerfile.dev. Then run:

$ rm -rf ./node_modules
$ docker-compose build --no-cache
$ docker-compose run --rm --no-deps api yarn
$ docker-compose up

All 5 comments

Possible duplicate of
https://github.com/GoogleCloudPlatform/google-cloud-node/issues/1820
and it was moved to
https://github.com/grpc/grpc/issues/8860

Although I was not able to get it working with any of the solutions in the thread

This issue was moved to grpc/grpc#12780

Thanks for reporting. I've moved the issue to the gRPC repository, as they're likely the right ones to find an answer. Sorry for the trouble.

@DaveyEdwards you can try to solve it by adding libc6-compat to Dockerfile and Dockerfile.dev. Then run:

$ rm -rf ./node_modules
$ docker-compose build --no-cache
$ docker-compose run --rm --no-deps api yarn
$ docker-compose up

@koistya This worked perfectly thanks!

my dockerfile now looks like:

FROM node:8.6.0-alpine

# Set a working directory
WORKDIR /usr/src/app

# Copy application files
COPY . .

# Install dependencies
RUN apk add --no-cache libsodium libc6-compat && \
  yarn install --production --no-progress && \
  yarn cache clean

# Run the container under "node" user by default
USER node

CMD [ "node", "build/server.js" ]

and the Dockerfile.dev

FROM node:8.6.0-alpine

# Set a working directory
WORKDIR /usr/src/app

# If you have native dependencies, you'll need extra tools
RUN apk add --no-cache make g++ python2 libsodium-dev libc6-compat && \
  npm install -g node-gyp && \
  mkdir -p /home/node/.cache/yarn && \
  chown -R node:node /home/node/.cache/yarn && \
  chmod 777 /home/node/.cache/yarn

VOLUME /home/node/.cache/yarn

# Run the container under "node" user by default
USER node
Was this page helpful?
0 / 5 - 0 ratings

Related issues

positlabs picture positlabs  路  3Comments

stephenplusplus picture stephenplusplus  路  4Comments

dsimmons picture dsimmons  路  4Comments

vvzen picture vvzen  路  4Comments

nicolasgarnier picture nicolasgarnier  路  4Comments