protobuf-javascript icon indicating copy to clipboard operation
protobuf-javascript copied to clipboard

Js TypeError when generated with commonjs_strict

Open Hunrik opened this issue 4 years ago • 3 comments

Version: v3.10.0 Language: Javascript OS: OSX 10.14.6 Node v12.10.0

When js files generated with commonjs_strict the referrences to types defined in other files are not using the package name to access it from the exported object, so TypeError is thrown due to reading property of undefined.

How to reproduce

a.proto

syntax = "proto3";

package foo.v1;
import "b.proto";

message A {
  repeated foo.v1.B foo = 1;
}

b.proto

syntax = "proto3";

package foo.v1;
import "b.proto";

message A {
  repeated foo.v1.B foo = 1;
}
protoc \
  --js_out=import_style=commonjs_strict:./generated \
  a.proto b.proto

In the generated js files the protos_b_pb.B should be protos_b_foo.v1.pb.B

Hunrik avatar Oct 25 '19 12:10 Hunrik