protocolbuffers / protocolbuffers/protobuf-javascript

Js TypeError when generated with commonjs_strict

Open
#40 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug good first issue javascript triaged
Dominant language
JavaScript
Stars
471
Forks
91
Avg merge
3h 57m
Merged PRs (30d)
2

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the provided a.proto, b.proto, and protoc command using commonjs_strict, then inspect the generated JavaScript references between the files. Trace how package-qualified exports are formed and verify that the generated reference uses the exported package path and no longer throws a TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
build-system, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.