Coder Social home page Coder Social logo

Comments (1)

Zoddo avatar Zoddo commented on July 17, 2024

As we say, things are clearer in the morning! I found out what's my issue.

This error is coming from this check in the compiled proto file:

if (!(arg instanceof google_protobuf_struct_pb.Struct)) {
  throw new Error('Expected argument of type google.protobuf.Struct');
}

Now, why this cause issues in my case?
In my project, compiled proto files are put in a separate package that is installed with npm (to prevent code duplication).

Basically:

my repo
|─ server
|   |─ package.json
|   `─ server.js
`─ lib/testproto
    |─ package.json
    |─ test.proto
    |─ test_grpc_pb.js
    `─ test_pb.js

So when in server, I npm I -S ../lib/testproto, npm generates a symlink like this:
node_modules/testproto -> ../../lib/cache

Because it's a symlink, module deduplication between server and testproto doesn't work, as shown by npm ls google-protobuf in server:

zoddo@arch:~/git/myproject/server$ npm ls google-protobuf
[email protected] /home/zoddo/git/myproject/server
├─┬ [email protected] -> ./../lib/testproto
│ ├── [email protected]
│ └─┬ [email protected]
│   └── [email protected] deduped
└── [email protected]

As such, compiled files in testproto don't use the same files than server when doing require('google-protobuf'), breaking the instanceof check done in the compiled proto file.

In other words, that means that in the server, I generated an instance of Struct coming from:

server/node_modules/google-protobuf/google/protobuf/struct_pb.js

...while in testproto, it is checking if it's an instance of Struct coming from:

lib/cache/node_modules/google-protobuf/google/protobuf/struct_pb.js

(while it's the same code in the 2 files, they are different objects for the JS engine)

I'm not sure how to properly fix this issue. We can't even check arg.constructor.name because Struct isn't a class, but an anonymous function.

Right now I have a workaround by using TestService.getStruct.responseType.fromJavaScript(myObj) instead of Struct.fromJavaScript(myObj), but that's a hacky solution I don't like at all!

from grpc-node.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.