Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/404.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何导入protoc生成的javascript?_Javascript_Meteor_Protocol Buffers - Fatal编程技术网

如何导入protoc生成的javascript?

如何导入protoc生成的javascript?,javascript,meteor,protocol-buffers,Javascript,Meteor,Protocol Buffers,我是protobuf的新手。 我已经安装了npm谷歌protobuf 下面是我的.proto文件 syntax = "proto3"; package com.sixdee; message Student{ string name = 1; int32 id = 2; } 这就是我如何生成.js文件的 protoc --js_out=import_style=commonjs,binary:. testproto.proto 我已经在我的项目中粘贴了生成的t

我是protobuf的新手。 我已经安装了npm谷歌protobuf

下面是我的.proto文件

syntax = "proto3";
package com.sixdee;
message Student{
        string name = 1;
        int32 id = 2;
}
这就是我如何生成.js文件的

protoc --js_out=import_style=commonjs,binary:. testproto.proto
我已经在我的项目中粘贴了生成的
testproto_pb.js
。 我无法构建protobuf数据包。 我试过了

var student = new Student();
student.setName("Ankith");
student.setId(24);
我得到未捕获的引用错误:未定义学生

我已经提到了。对我来说似乎什么都不管用。
非常感谢您的帮助。

我不确定我们的代码有什么问题。没有完整的源代码很难判断

我使用了npm的protobufjs,如下所述:


前端也需要protobuf库。

如果您使用CommonJS风格的导入,那么我认为您应该这样做:var testproto_pb=require('./testproto_pb.js');var student=newtestproto_pb.student()。。。这样行吗?