protovalidate icon indicating copy to clipboard operation
protovalidate copied to clipboard

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

Open gurleensethi opened this issue 1 year ago • 1 comments

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 avatar Sep 14 '24 18:09 gurleensethi

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.

timostamm avatar Sep 16 '24 08:09 timostamm

Hi! Connect-ES no longer needs its own code generator plugin, so I think you can close this issue, right?

StevenACoffman avatar Dec 23 '24 23:12 StevenACoffman

with include_imports: true generated the import are generated outside of the project dir. is there way to generate it inside? and this validate_pb is protovalidate-es?? @timostamm

singh-hovr avatar Jan 03 '25 00:01 singh-hovr

We are struggling with the same issue. The import seems to be generated relative with a "random" path. Is there any doc/pointer on how the resolution is expected to work?

guw avatar Sep 16 '25 17:09 guw