我找不到与我相同或相近的问题。我在做一个RFID gRPC服务。我的包名是rfidgrpc,它在项目中是唯一的。但我仍然得到意外的标识符错误。顺便说一句,我是新的与这个gRPC的事情。以下是我的proto:
syntax = "proto3";
package rfidgrpc;
service RFIDService {
rpc ReadRFID (RFIDRequest) returns (RFIDResponse) {}
}
message RFIDRequest {}
message RFIDResponse {
string tag = 1;
}
下面是我的server.js:
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const SerialPort = require('serialport').SerialPort;
const {ReadlineParser} = require('@serialport/parser-readline');
var PROTO_PATH = `${__dirname}/rfid.proto`;
const RFIDService = require('./RFIDService');
// Load the protobuf file
var packageDefinition = protoLoader.loadSync(
PROTO_PATH,
{keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
});
// Load the gRPC package
//const rfidProto = grpc.loadPackageDefinition(packageDefinition).grpcserv;
const rfidProto = require('./rfid.proto');
// Create the gRPC server
function main() {
var server = new grpc.Server();
//servis oluşturma
server.addService(rfidProto.RFIDService.service, { readTag: RFIDService.prototype.readTag });
//gRPC bağlantısı oluşturma
server.bindAsync("127.0.0.1:5000", grpc.ServerCredentials.createInsecure(), (err) => {
server.start();
console.log("GRPC Server 5000 üzerinde başlatıldı.....");
});
}
main();
下面是错误:
package rfidgrpc;
^^^^^^^^
SyntaxError: Unexpected identifier
at Object.compileFunction (node:vm:360:18)
at wrapSafe (node:internal/modules/cjs/loader:1049:15)
at Module._compile (node:internal/modules/cjs/loader:1084:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1174:10)
at Module.load (node:internal/modules/cjs/loader:998:32)
at Module._load (node:internal/modules/cjs/loader:839:12)
at Module.require (node:internal/modules/cjs/loader:1022:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (C:\Users\Nur Seda\Desktop\rfid_grpc\server.js:20:19)
at Module._compile (node:internal/modules/cjs/loader:1120:14)
我检查了package.json文件。软件包名称之间没有区别。我没有使用任何特殊字符。
1条答案
按热度按时间hgb9j2n61#
试试这个:
使用gRPCurl测试: