Skip to content

Generated code imports from a non-existent file when using the Opaque API instead of WKT #1123

@ernestoalejo

Description

@ernestoalejo

When using an external protobuf that enables the Go Opaque API, the generated code imports from a location that doesn't exist instead of the well known type.

Timo explained it better:

when we added support for Editions to Protobuf-ES, the go_features.proto file was not part of the well-known types. This was changed some time ago, and the file is now part of the well-known types, and ships with Protobuf compilers.

Reproduction

For example given this proto:

edition = "2023";

package foo.bar;

import "google/protobuf/go_features.proto";
option features.(pb.go).api_level = API_OPAQUE;

service FooService {
  rpc Get(Foo) returns (Foo) {}
}

message Foo {
}

When installed through NPM remote generation with the latest version:

pnpm add @buf/[email protected]

The generated code includes this import, which isn't present in the node_modules package:

import { file_google_protobuf_go_features } from "../google/protobuf/go_features_pb.js";

Proposed workaround until the fix

For the benefit of anyone finding this issue before a fix is released, here is the workaround proposed by Timo:

As a workaround, you can temporarily switch to local code generation, and strip the option features.(pb.go) before generating code with exclude_types in buf.gen.yaml:

# ...
plugins:
  - local: protoc-gen-es
    opt: target=ts
    out: src/gen
    exclude_types:
      - pb.go

In our case, the repository using the package doesn't work with Buf and doesn't have any protos or related infrastructure, so we applied a pnpm patch to the file instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions