-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generated code not importing from buf for a dependency #947
Comments
Hey Jeremy, generated SDKs are great if you only need the generated code, and do not want to generate code yourself. In your case, the most simple solution is to include imports when generating: - local: protoc-gen-connect-es
+ include_imports: true
opt:
- target=ts This will generate just the files you need from Unfortunately, Protobuf does not define an equivalent to the We do have a mechanism to do something equivalent - the plugin option - local: protoc-gen-connect-es
opt:
- target=ts
+ - rewrite_imports=./runme/**/*_pb.js:@buf/stateful_runme.bufbuild_es This option will change the generated imports as follows: - import { Cell, Notebook } from "../../runme/parser/v1/parser_pb";
+ import { Cell, Notebook } from "@buf/stateful_runme.bufbuild_es/runme/parser/v1/parser_pb"; It's reliable and stable, but you may run into issues with bundlers because of things like import extensions. The ecosystem is in flux, and no single way of doing things exists yet. The message |
The rewriter_imports issue solved my issue. Thank you very much. |
I'm using buf to define some protos which depend on the module buf.build/stateful/runme.
My expectation is that the generated code would import the stateful typescript client i.e. something like
But that's not what's happening. Instead its using an import
That suggests its trying to generate the SDK for the dependency rather than importing the SDK for the dependency.
Here is my buf.yaml
I was originally using v1 but migrated to v2 to try to experiment with managed mode. But then I realized I didn't know what option to set to control the import used for a proto. Is there an option similar to go_package that controls what the import for the proto would be?
The stateful/runme protos I want to depend on are defined here.
I looked at the example and it seems like it correctly generates the import for the google timestamp proto here. I was confused about how thats working since I couldn't find a
buf.yaml
file in that repository.The text was updated successfully, but these errors were encountered: