protocolbuffers / protocolbuffers/protobuf-javascript
Public import is not included in generated CommonJS file
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- JavaScript
- Sterne
- 471
- Forks
- 91
- Ø Merge
- 3 Std. 57 Min.
- Gemergte PRs (30 T.)
- 2
Beschreibung
System
Version: v3.6.1
Language: Javascript
macOS 10.14
Steps to reproduce
- Create a
srcdirectory with 3 files:// id.proto syntax = "proto3"; message Id { string value = 1; }// task.proto adding a transitive import for `Id` syntax = "proto3"; import public "id.proto"; message Task { Id id = 1; }// project.proto importing both `Id` and `Task` from Project syntax = "proto3"; import "task.proto"; message Project { Id id = 1; repeated Task task = 2; } - Compile to js using
mkdir build protoc --proto_path=src --js_out=import_style=commonjs,binary:build id.proto task.proto project.proto npm install google-protobufunder the root directory.node test.js// test.js var id_pb = require('./build/id_pb'); var project_pb = require('./build/project_pb'); var id = new id_pb.Id(); id.setValue("Everything is fine"); var project = new project_pb.Project() project.setId(id); process.stdout.write(project.getId().getValue()); process.stdout.write("\n");
Expected behaviour
Everything is fine is printed to the console.
Actual behaviour
.../test-proto/build/project_pb.js:173
jspb.Message.getWrapperField(this, id_pb.Id, 1));
^
ReferenceError: id_pb is not defined
at proto.Project.getId (.../test-proto/build/project_pb.js:173:40)
at Object.<anonymous> (.../test-proto/test.js:10:30)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
at startup (internal/bootstrap/node.js:285:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)
id_pb import is missing from project_pb. Alternatively it may be referenced from task_pb, since it’s declared public in task.proto.
The error does not show up if id.proto is explicitly imported in project.proto.
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Reproduziere den Fall mit dem bereitgestellten protoc-Befehl und untersuche anschließend build/project_pb.js sowie die generierten Imports für id_pb und task_pb. Verwende test.js, um das Verhalten zu überprüfen; fertig ist es, wenn der transitive öffentliche Import für project_pb.js verfügbar ist und das Skript „Everything is fine“ ausgibt, ohne dass ein expliziter Import in project.proto erforderlich ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript
- Bereich
- tooling
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100