camunda-community-hub / zeebe-client-node-js

Node.js client library for Zeebe Microservices Orchestration Engine
https://camunda-community-hub.github.io/zeebe-client-node-js/
Apache License 2.0
152 stars 38 forks source link

Unable to use library with external builds - zeebe.proto file path passed to proto.path #299

Closed BaluVyamajala closed 1 year ago

BaluVyamajala commented 1 year ago

When library is used in applications which uses external builds , direct references to files example: https://github.com/camunda-community-hub/zeebe-client-node-js/blob/master/src/zb/ZBClient.ts#L1292 throwing errors.

Current Behavior

Error: ENOENT: no such file or directory, open '/Users/myUser/proto/zeebe.proto'
    at Object.openSync (node:fs:600:3)
    at Object.readFileSync (node:fs:468:35)
    at fetch (/Users/myUser/camunda-zrpc-test/dist/out.js:31582:30)
    at Root.load (/Users/myUser/camunda-zrpc-test/dist/out.js:31611:11)
    at Root.loadSync (/Users/myUser/camunda-zrpc-test/dist/out.js:31621:19)
    at loadProtosWithOptionsSync (/Users/myUser/camunda-zrpc-test/dist/out.js:35023:31)
    at loadSync (/Users/myUser/camunda-zrpc-test/dist/out.js:36043:63)
    at new GrpcClient (/Users/myUser/camunda-zrpc-test/dist/out.js:44115:62)
    at GrpcMiddleware.createInterceptedGrpcClient (/Users/myUser/camunda-zrpc-test/dist/out.js:44455:28)
    at new GrpcMiddleware (/Users/myUser/camunda-zrpc-test/dist/out.js:44452:32) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/Users/myUser/proto/zeebe.proto'
}

Possible solutions

Rather than directly referencing a path to a file. we could use require/import the file and use it.

Steps to Reproduce

Sample Repo https://github.com/BaluVyamajala/camunda-zrpc-esbuild-test

npm run build
node dist/out.js 
jwulf commented 1 year ago

Just out of curiosity, what's the motivation for using ESBuild on Node?

BaluVyamajala commented 1 year ago

Just out of curiosity, what's the motivation for using ESBuild on Node?

Currently we are building a lambda function in AWS and to make these efficient, we build a minified file making it super small and without including entire node_modules folder. For example https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda_nodejs-readme.html library uses esbuild behind the scenes.

jwulf commented 1 year ago

OK. I've done this before. From memory: you need to add a build step to move the proto file. Since it is dynamically loaded and is not a .js asset, the builder needs to be made aware of it.

jwulf commented 1 year ago

See, for example:

https://github.com/open-telemetry/opentelemetry-js/issues/2786#issuecomment-1088796793 https://github.com/open-telemetry/opentelemetry-js/issues/2887

jwulf commented 1 year ago

I'm going to close this for now. If you figure out a way to do this, let me know.