我正在研究this node / grpc示例。我能够得到" dynamic_codegen"工作的例子,现在尝试static_codegen。
我的目录结构看起来像这样。
- grpc/
- examples/
- node/
- static_codegen/
greeter_client.js
greeter_server.js
helloworld_grpc_pb.js
helloworld_pb.js
README.md
route_guide/
- node_modules/
- google-protobuf/
package.json
<other packages and files>
正如您所看到的,google-protobuf模块看起来应该可用于helloworld_pb.js,正如我发现的here规则所述。但是,当我去运行程序时
>> node greeter_server.js
我得到以下堆栈跟踪。
module.js:471
throw err;
^
Error: Cannot find module 'google-protobuf'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/tmp/grpc/examples/node/static_codegen/helloworld_pb.js:10:12)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
我不确定如何让google-protobuf模块可以被发现,比我已经拥有的更多。
我应该提到我正在运行节点6.12.0,npm 3.10.10
编辑1:
在生成的代码中,模块需要如下所示
/**
* @fileoverview
* @enhanceable
* @public
*/
// GENERATED CODE -- DO NOT EDIT!
var jspb = require('google-protobuf');
编辑2:我发现了
中的package.jsonnode_modules/google-protobuf/package.json
引用一个不存在的文件。
"main": "google-protobuf.js",
我的文件夹看起来像这样
├── google
│ └── protobuf
│ ├── any_pb.js
│ ├── api_pb.js
│ ├── compiler
│ │ └── plugin_pb.js
│ ├── descriptor_pb.js
│ ├── duration_pb.js
│ ├── empty_pb.js
│ ├── field_mask_pb.js
│ ├── source_context_pb.js
│ ├── struct_pb.js
│ ├── timestamp_pb.js
│ ├── type_pb.js
│ └── wrappers_pb.js
├── package.json
└── README.md
google-protobuf.js无处可寻。我最初通过在我的主项目的package.json上运行npm install来获得这种依赖,看起来像这样。
{
"name": "node-example",
"version": "0.1.0",
"main": "test.js",
"dependencies": {
"async": "^1.5.2",
"google-protobuf": "^3.0.0",
"grpc": "^1.0.0",
"lodash": "^4.6.1",
"minimist": "^1.2.0"
}
}
所以现在我不确定为什么google-protobuf.js文件不会与模块的其余部分一起被拉下来。当我触摸&#34;在正确的目录中的google-protobuf.js,我得到了一个不同的错误,所以我相信这是基于该文件不在那里。