TypeError:util.Long.fromValue不是一个函数-VoidCC

时间:2019-01-11 12:36:28

标签: node.js stackdriver google-cloud-logging

请阅读:如果您与Google有支持合同,请在support console中创建问题,而不要在GitHub上提交。这样可以确保及时响应。

    process.env.GOOGLE_APPLICATION_CREDENTIALS="path to the credentials";
    const {Logging} = require('@google-cloud/logging');

    const logging = new Logging({
      projectId: "projectId"
    });

    const logName = 'my-log';
    const log = logging.log(logName);

    const text = 'Hello, world!';
    const metadata = {resource: {type: 'global'}};

    const entry = log.entry(metadata, text);

    log
      .write(entry)
      .then(() => {
        console.log(`Logged: ${text}`);
      })
      .catch(err => {
        console.error('ERROR:', err);
      });

我收到此错误

undefined:9
  (m.seconds=util.Long.fromValue(d.seconds)).unsigned=false
                       ^

TypeError: util.Long.fromValue is not a function
    at Type.Timestamp$fromObject [as fromObject] (eval at Codegen (/home/admin/Documents/projects/new-kroger-api/node_modules/@protobufjs/codegen/index.js:50:33), <anonymous>:9:24)
    at Type.fromObject (/home/admin/Documents/projects/new-kroger-api/node_modules/protobufjs/src/type.js:538:25)
    at Type.LogEntry$fromObject [as fromObject] (eval at Codegen (/home/admin/Documents/projects/new-kroger-api/node_modules/@protobufjs/codegen/index.js:50:33), <anonymous>:31:24)
    at Type.fromObject (/home/admin/Documents/projects/new-kroger-api/node_modules/protobufjs/src/type.js:538:25)
    at Type.WriteLogEntriesRequest$fromObject [as fromObject] (eval at Codegen (/home/admin/Documents/projects/new-kroger-api/node_modules/@protobufjs/codegen/index.js:50:33), <anonymous>:30:25)
    at Type.fromObject (/home/admin/Documents/projects/new-kroger-api/node_modules/protobufjs/src/type.js:538:25)
    at serialize (/home/admin/Documents/projects/new-kroger-api/node_modules/grpc/src/protobuf_js_6_common.js:71:23)
    at Object.final_requester.sendMessage (/home/admin/Documents/projects/new-kroger-api/node_modules/grpc/src/client_interceptors.js:806:37)
    at InterceptingCall._callNext (/home/admin/Documents/projects/new-kroger-api/node_modules/grpc/src/client_interceptors.js:419:43)
    at InterceptingCall.sendMessage (/home/admin/Documents/projects/new-kroger-api/node_modules/grpc/src/client_interceptors.js:464:8)
    at InterceptingCall._callNext (/home/admin/Documents/projects/new-kroger-api/node_modules/grpc/src/client_interceptors.js:428:12)
    at InterceptingCall.sendMessage (/home/admin/Documents/projects/new-kroger-api/node_modules/grpc/src/client_interceptors.js:464:8)
    at ServiceClient.Client.makeUnaryRequest (/home/admin/Documents/projects/new-kroger-api/node_modules/grpc/src/client.js:536:21)
    at ServiceClient.method_func (/home/admin/Documents/projects/new-kroger-api/node_modules/grpc/src/client.js:950:43)
    at /home/admin/Documents/projects/new-kroger-api/node_modules/@google-cloud/logging/build/src/v2/logging_service_v2_client.js:188:39
    at Task.timeoutFunc [as _apiCall] (/home/admin/Documents/projects/new-kroger-api/node_modules/google-gax/build/src/api_callable.js:143:16)
    at Task.run (/home/admin/Documents/projects/new-kroger-api/node_modules/google-gax/build/src/bundling.js:195:18)
    at BundleExecutor._runNow (/home/admin/Documents/projects/new-kroger-api/node_modules/google-gax/build/src/bundling.js:421:14)
    at Timeout._timers.(anonymous function).setTimeout [as _onTimeout] (/home/admin/Documents/projects/new-kroger-api/node_modules/google-gax/build/src/bundling.js:367:22)
    at ontimeout (timers.js:436:11)
    at tryOnTimeout (timers.js:300:5)
    at listOnTimeout (timers.js:263:5

此错误发生在位置log.write,我不知道为什么会引发此错误,请帮助我

1 个答案:

答案 0 :(得分:0)

在lambda函数中使用Google Firebase节点api时,我也发生了同样的错误。 发生这种情况是由于模块全局覆盖了Long类型的protobuf.js。它很可能是long模块的旧版本。即使您的package.json中没有此模块,也可能将其作为另一个模块的依赖项进行加载。

就我而言,某些依赖项正在使用long 1.1.2。并且protobuf.js需要long 4.0.0。较新的node&npm版本在执行npm install

时应自动解决此冲突

但是,我通过直接在long文件夹内升级node_modules来解决此问题。或者,您也可以在package_lock.json文件中进行操作。

以下问题对此进行了详细说明:https://github.com/googleapis/nodejs-firestore/issues/336