Skip to content
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

[BUG] Upgrading to v2 buf generates an import statement for JavaScript/Typescript that doesn't exist. #253

Open
gurleensethi opened this issue Sep 14, 2024 · 1 comment
Labels
Bug Something isn't working

Comments

@gurleensethi
Copy link

gurleensethi commented Sep 14, 2024

Description

One of the generated import statement:

import { file_buf_validate_validate } from "../buf/validate/validate_pb";

I get the error:

Cannot find module '../buf/validate/validate_pb' or its corresponding type declarations.

buf.yaml file:

version: v2
modules:
  - path: proto
    lint:
      use:
        - DEFAULT
      except:
        - FIELD_NOT_REQUIRED
        - PACKAGE_DIRECTORY_MATCH
        - PACKAGE_NO_IMPORT_CYCLE
      disallow_comment_ignores: true
    breaking:
      use:
        - FILE
      except:
        - EXTENSION_NO_DELETE
        - FIELD_SAME_DEFAULT
deps:
  - buf.build/bufbuild/protovalidate

buf.gen.yaml file:

version: v2
plugins:
  - remote: buf.build/protocolbuffers/go
    out: gen/go
    opt: paths=source_relative
  - remote: buf.build/connectrpc/go
    out: gen/go
    opt: paths=source_relative
  - remote: buf.build/bufbuild/es
    out: gen/es
    opt: target=ts
  - remote: buf.build/connectrpc/es
    out: gen/es
    opt: target=ts
  - remote: buf.build/bufbuild/es
    out: ./services/tdc-ui/app/api/gen
    opt: target=ts
  - remote: buf.build/connectrpc/es
    out: ./services/tdc-ui/app/api/gen
    opt: target=ts

Steps to Reproduce

Expected Behavior

Actual Behavior

Screenshots/Logs

Environment

  • Operating System:
  • Version:
  • Compiler/Toolchain:
  • Protobuf Compiler & Version:
  • Protoc-gen-validate Version:
  • Protovalidate Version:

Possible Solution

Additional Context

@gurleensethi gurleensethi added the Bug Something isn't working label Sep 14, 2024
@gurleensethi gurleensethi changed the title [BUG] Upgrading to v2 buf generates an import statement for JavaScript/Typescript generate that doesn't exist. [BUG] Upgrading to v2 buf generates an import statement for JavaScript/Typescript that doesn't exist. Sep 14, 2024
@timostamm
Copy link
Member

Hey Gurleen, we recently release version 2 of buf.build/bufbuild/es. The plugin for Connect buf.build/connectrpc/es has not been updated to support it yet.

Can you pin the versions of the plugins in your buf.gen.yaml file?

version: v2
plugins:
  - remote: buf.build/protocolbuffers/go
    out: gen/go
    opt: paths=source_relative
  - remote: buf.build/connectrpc/go
    out: gen/go
    opt: paths=source_relative
- - remote: buf.build/bufbuild/es
+ - remote: buf.build/bufbuild/es:v1.10.0
    out: gen/es
    opt: target=ts
- - remote: buf.build/connectrpc/es
+ - remote: buf.build/connectrpc/es:v1.5.0
    out: gen/es
    opt: target=ts
- - remote: buf.build/bufbuild/es
+ - remote: buf.build/bufbuild/es:v1.10.0
    out: ./services/tdc-ui/app/api/gen
    opt: target=ts
- - remote: buf.build/connectrpc/es
+ - remote: buf.build/connectrpc/es:v1.5.0
    out: ./services/tdc-ui/app/api/gen
    opt: target=ts

This should solve the issue.

From what I see, the issue is as follows:

  • You import buf/validate/validate.proto to set validation options.
  • Version 1 of buf.build/bufbuild/es does not support the custom options, and ignores the import.
  • Version 2 however does support them, and generates the import for ../buf/validate/validate_pb.
  • By default buf generate does not generate code for imports to module dependencies, so the file does not exist.

The solution for this issue is to add include_imports: true to the plugin config (see docs) - but since we haven't finished updating Connect yet, the code would fail to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants