收藏
回答

grpc在小程序云函数中无法使用,求帮助

框架类型 问题类型 终端类型 AppID 基础库版本
小游戏 Bug 工具 wx8df285501e7d37dd 2.8.1
exports.main = async (event, context) => {
  var PROTO_PATH = __dirname + '/protos/route_guide.proto';
 
  var async = require('async');
  var fs = require('fs');
  var parseArgs = require('minimist');
  var path = require('path');
  var _ = require('lodash');
  var grpc = require('grpc');
  var protoLoader = require('@grpc/proto-loader');
  var packageDefinition = protoLoader.loadSync(
    PROTO_PATH,
    {
      keepCase: true,
      longs: String,
      enums: String,
      defaults: true,
      oneofs: true
    });
  var routeguide = grpc.loadPackageDefinition(packageDefinition).routeguide;
  var client = new routeguide.RouteGuide('打码的ip地址:50051', grpc.credentials.createInsecure());
  var COORD_FACTOR = 1e7;
 
  var point1 = {
    latitude: 409146138,
    longitude: -746188906
  };
  client.getFeature(point1, function (err, feature){
      if(err){
        return err;
      }else{
        return true;
      }
  });
  return {ok:1}
}

上面是的云函数代码,云端测试后,报错返回接口如下:

{"errorCode":1,"errorMessage":"user code exception caught","stackTrace":"channel.createCall is not a function"}


为什么会这样?grpc接口,在本地测试是成功的。但是放到云函数上就不成功了。

调用日志如下:

调用日志
START RequestId: 2977fa93-c8e2-11e9-855a-525400dee61a
 
Event RequestId: 2977fa93-c8e2-11e9-855a-525400dee61a
 
TypeError: channel.createCall is not a function
 
    at getCall (/var/user/node_modules/grpc/src/client_interceptors.js:655:22)
 
    at /var/user/node_modules/grpc/src/client_interceptors.js:788:16
 
    at /var/user/node_modules/grpc/src/client_interceptors.js:1397:14
 
    at _buildChain (/var/user/node_modules/grpc/src/client_interceptors.js:1400:33)
 
    at Object.getInterceptingCall (/var/user/node_modules/grpc/src/client_interceptors.js:1362:10)
 
    at ServiceClient.Client.makeUnaryRequest (/var/user/node_modules/grpc/src/client.js:568:47)
 
    at ServiceClient.method_func (/var/user/node_modules/grpc/src/client.js:1000:43)
 
    at EventHandler.exports.main [as realHandler] (/var/user/index.js:46:10)
 
    at EventHandler.handle (/var/runtime/node8/bootstrap.js:323:28)
 
    at invoke (/var/runtime/node8/bootstrap.js:128:22)
 
END RequestId: 2977fa93-c8e2-11e9-855a-525400dee61a
 
Report RequestId: 2977fa93-c8e2-11e9-855a-525400dee61a Duration:2ms Memory:256MB MaxMemoryUsed:39.062500MB


然后追查到client_interceptors.js getCall代码显示是这样:


最后一次编辑于  2019-08-27
回答关注问题邀请回答
收藏

1 个回答

  • 邓坤力
    邓坤力
    2019-08-29

    有用云端安装依赖上传吗

    2019-08-29
    有用
    回复 2
    • 6🤓
      6🤓
      2019-09-02
      有的。
      2019-09-02
      回复
    • 笨笨
      笨笨
      2020-01-10
      最后解决了么   楼主
      2020-01-10
      回复
登录 后发表内容
问题标签