GoogleCloudPlatform / grpc-gcp-node

Apache License 2.0
18 stars 16 forks source link

Missing transitive dependency on protobufjs #166

Open maxmil opened 1 year ago

maxmil commented 1 year ago

When using the library with Yarn 3 (via google-cloud/spanner) module resolution is failing at runtime because protobufjs/minimal is referenced from build/src/generated/ but the transitive dependency on protobufjs is not declared in package json.

Error: grpc-gcp tried to access protobufjs, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Required package: protobufjs (via "protobufjs/minimal")
Required by: grpc-gcp@npm:1.0.1 (via /.yarn/cache/grpc-gcp-npm-1.0.1-d26546ce0e-ad6608b982.zip/node_modules/grpc-gcp/build/src/generated/)

Require stack:
- .yarn/cache/grpc-gcp-npm-1.0.1-d26546ce0e-ad6608b982.zip/node_modules/grpc-gcp/build/src/generated/grpc_gcp.js
- .yarn/cache/grpc-gcp-npm-1.0.1-d26546ce0e-ad6608b982.zip/node_modules/grpc-gcp/build/src/index.js
- .yarn/cache/@google-cloud-spanner-npm-6.11.0-4009155329-6a21287f0f.zip/node_modules/@google-cloud/spanner/build/src/index.js
- workspaces/common/src/cloud-spanner.ts

Environment details

Steps to reproduce

  1. Create a project with the following package.json
    {
    "name": "test-spanner-nodejs",
    "version": "1.0.0",
    "dependencies": {
    "@google-cloud/spanner": "^6.11.0"
    },
    "packageManager": "yarn@3.6.0"
    }
  2. yarn install
  3. Copy main.js
    (async () => {
    const {Spanner} = require('@google-cloud/spanner');
    const spanner = new Spanner({projectId: 'your-project-id'});
    await spanner.instance("your-instance").database("your-database").run("select 1")
    })()
  4. yarn node main.js

You should see the error above. Adding "protobufjs": "^7.2.3" to the dependencies in package.json fixes the problem.

maxmil commented 1 year ago

The dependency is used on line 4 of src/generated/igrpc_gcp.js