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

Well known proto3 types missing from npm package #1638

Closed
KeithWoods opened this issue Jun 1, 2016 · 4 comments
Closed

Well known proto3 types missing from npm package #1638

KeithWoods opened this issue Jun 1, 2016 · 4 comments
Assignees
Labels
Milestone

Comments

@KeithWoods
Copy link

Hi All

I'm using proto3 with the last beta 3 (v3.0.0-beta-3) to generate javascript DTOS as CommonJs modules.

In the generated javascript, built in proto type (e.g. google.protobuf.Timestamp) are 'required' but don't exist.

For example, given this proto:

// file: foo.proto
syntax = "proto3";

import "google/protobuf/timestamp.proto";

message SomeMessage {
   google.protobuf.Timestamp someTime = 1;
}

And this command:

protoc --proto_path=./ --js_out=import_style=commonjs:./ foo.proto

we get this output:

// file: foo_pb.js
/**
* @fileoverview
* @enhanceable
* @public
*/
// GENERATED CODE -- DO NOT EDIT!

var jspb = require('google-protobuf');
var goog = jspb;
var global = Function('return this')();

var google_protobuf_timestamp_pb = require('./google/protobuf/timestamp_pb.js'); // NOTE ./google/protobuf/timestamp_pb.js doesn't exist
goog.exportSymbol('proto.SomeMessage', null, global);

The file timestamp_pb.js isn't generated (note timestamp.proto does exist under my protoc executable) thus doesn't exist at the generated path.

I'd expect it to exist in the google-protobuf npm package, e.g. the generated code should be require('google-protobuf/somePathHere/timestamp_pb.js').

First reported on google groups, it was suggested I create this issue.

@haberman
Copy link
Member

The well-known types are in the npm package now.

@mohannarang
Copy link

When I use NPM package to get well know know types, it gives the file with import style as commonjs.

How do I get well know types for import style closure?

@acozzette
Copy link
Member

@thefunnyguy I think for now you just have to build the well-known types manually with protoc if you want to use Closure-style imports. We could potentially consider including both import styles in the NPM package, though. What does your build setup look like?

@mohannarang
Copy link

@acozzette

Some of my proto files are using "import "google/protobuf/timestamp.proto";"

I am using bazel build system so all code is closure style. Initially I tried using "closure_js_proto_library" rule to covert my protos to closure style. But well known types are not available, so its failing.

I ended up running the below command to generate JS file:
protoc --proto_path=./proto-folder/ --js_out=library=proto_lib,binary:. ./proto-folder/*.proto

But still goog.require for well known type fails as those closure style files are not available.

I thought to get those file using NPM, but the files are in commonjs style, so google require statements are still failing.

I ended up taking the whole google protobuf folder and compiled the proto files using protoc, something like:
proto_path=./protobuf/src/google/protobuf/ --js_out=library=well_known_proto_libs,binary:. ./protobuf/src/google/protobuf/timestamp.proto

This seems to resolve the errors for now, but not sure if that's the correct way. Having closure style NPM package will make life easy i guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants