环境:
问题:
创建gRPC数据源时,它不会读取原型文件并引发错误
错误:
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
按照步骤,下载连接器,再次出现同样的错误。
答案 0 :(得分:0)
我找到了,我刚刚移动了proto文件目录。 它必须位于项目根目录
中