Strongloop/Loopback gRPC 连接器

Strongloop/Loopback connector for gRPC

环境:

问题:

创建 gRPC 数据源时,它不读取 proto 文件并抛出错误

错误:

if (err) throw err;^
TypeError: Cannot initialize connector "loopback-connector-grpc": Cannot read property 'ns' of null
    at Object.load (C:\Projects\GRPC\loopback-grpc\Server\node_modules\grpc\src\node\index.js:161:28)
    at GRPCConnector.connect (C:\Projects\GRPC\loopback-grpc\Server\node_modules\loopback-connector-grpc\lib\grpc-connector.js:71:21)
    at Object.initializeDataSource [as initialize] (C:\Projects\GRPC\loopback-grpc\Server\node_modules\loopback-connector-grpc\lib\grpc-connector.js:25:15)
    at DataSource.setup (C:\Projects\GRPC\loopback-grpc\Server\node_modules\loopback-datasource-juggler\lib\datasource.js:416:19)
    at new DataSource (C:\Projects\GRPC\loopback-grpc\Server\node_modules\loopback-datasource-juggler\lib\datasource.js:122:8)
    at Registry.createDataSource (C:\Projects\GRPC\loopback-grpc\Server\node_modules\loopback\lib\registry.js:360:12)
    at Function.loopback.createDataSource (C:\Projects\GRPC\loopback-grpc\Server\node_modules\loopback\lib\loopback.js:339:41)
    at Object.module.exports [as func] (C:\Projects\GRPC\loopback-grpc\Server\server\boot\server.js:9:21)
    at C:\Projects\GRPC\loopback-grpc\Server\node_modules\loopback-boot\lib\executor.js:316:22
    at iterate (C:\Projects\GRPC\loopback-grpc\Server\node_modules\loopback-boot\node_modules\async\lib\async.js:146:13)
    at C:\Projects\GRPC\loopback-grpc\Server\node_modules\loopback-boot\node_modules\async\lib\async.js:157:25
    at C:\Projects\GRPC\loopback-grpc\Server\node_modules\loopback-boot\lib\executor.js:321:9
    at iterate (C:\Projects\GRPC\loopback-grpc\Server\node_modules\loopback-boot\node_modules\async\lib\async.js:146:13)
    at C:\Projects\GRPC\loopback-grpc\Server\node_modules\loopback-boot\node_modules\async\lib\async.js:157:25
    at C:\Projects\GRPC\loopback-grpc\Server\node_modules\loopback-boot\lib\executor.js:321:9
    at iterate (C:\Projects\GRPC\loopback-grpc\Server\node_modules\loopback-boot\node_modules\async\lib\async.js:146:13)

复制步骤:

我刚刚阅读了 loopback-connector-grpc 官方存储库中的文档。

我用代码试过了,它没有创建数据源

var ds = loopback.createDataSource('grpc', {
    connector: 'loopback-connector-grpc',
    spec: 'note.proto',
});

我也试过这个:

"gRPCDataSource": {
    "name": "gRPCDataSource",
    "connector": "grpc",
    "spec": "note.proto",
    "security": {
      "type" : "basic", 
      "username": "the user name",
      "password": "thepassword"
} 

但还是一样的结果。

我也使用了这个命令lb datasource按照步骤,下载了连接器,同样的错误。

找到了,我只是移动了proto文件目录。 它必须在项目根目录