我正在为这个错误而苦苦挣扎:
TS2307: Cannot find module './google/api/annotations_pb'
事实上,我有这个protobuf:
syntax = "proto3";
package ChatAPI;
import "google/api/annotations.proto";
option go_package = "ChatAPI";
//
// The Chat API service definition.
//
service ChatAPIService {
rpc HelloWorld (HelloWorldRequest) returns (HelloWorldResponse) { option (google.api.http) = { post: "/hello_world" body:"*" }; }
}
//
// Chat API service parameters/returns data definition.
//
message HelloWorldRequest {
string name = 1;
}
message HelloWorldResponse {
string response = 1;
}
我的Go后端在REST部分上工作正常。我现在将我的ReactJs TypeScript连接到我的后端,所以我生成了protobuf的TypeScript输出:
# Path to this plugin
PROTOC_GEN_TS_PATH="/usr/local/lib/node_modules/ts-protoc-gen/bin/protoc-gen-ts"
protoc ${protofile} --proto_path . --plugin="protoc-gen-ts="${PROTOC_GEN_TS_PATH} --proto_path ${GOSRC}/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --grpc-web_out=import_style=typescript,mode=grpcwebtext:.
一切都正确生成,但是运行时出现了上述问题:
/Users/USERXX/PathToProject/my-app/src/app/stub/Chat-apiServiceClientPb.ts中的错误
./ app / stub / Chat-apiServiceClientPb.ts [tsl]
/Users/USERXX/PathToProject/my-app/src/app/stub/Chat-apiServiceClientPb.ts(12,44)中的错误
TS2307:找不到模块“ ./google/api/annotations_pb”。