0

PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.

    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);
      });

I am getting this error

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

this error is occurring at position log.write I don't know why it is throwing this error please help me

VAMSI AILA
  • 61
  • 1
  • 13

1 Answers1

4

This same error was happening to me using google firebase node api in a lambda function. This was happening due to a module globally overwriting the Long type of protobuf.js. It is most likely and old version of the long module. Even if you do not have this module in your package.json, it could be being loaded as a dependency of another module.

In my case, some dependency was using long 1.1.2. And protobuf.js needed long 4.0.0. Newer node & npm versions should automatically solve this collisions when doing npm install

However, I solved it by upgrading long directly inside the node_modules folder. Or you can also do it inside package_lock.json file.

The following issue explain this in detail: https://github.com/googleapis/nodejs-firestore/issues/336

Leonardo Kuffo
  • 901
  • 9
  • 10
  • 1
    I was facing this issue while creating grpc client in node js and installing long 4.0.0 in package.json solved my issue, thanks man you saved my hours because i had no clue why that was happening. – himanshu_chawla Jul 29 '20 at 14:30