profile
viewpoint

Ask questionsUnhandledPromiseRejectionWarning: TypeError: extend must be a string

Node Version: 14.17.5 NPM Version: 6.14.14 @google-cloud/logging-bunyan Version: 3.1.1

UnhandledPromiseRejectionWarning: TypeError: extend must be a string
at new Field (/usr/src/app/node_modules/protobufjs/src/field.js:79:15)
at fromJSON (/usr/src/app/node_modules/protobufjs/src/field.js:38:12)
at fromJSON (/usr/src/app/node_modules/protobufjs/src/type.js:247:31)
at Namespace.addJSON (/usr/src/app/node_modules/protobufjs/src/namespace.js:182:39)
at fromJSON (/usr/src/app/node_modules/protobufjs/src/namespace.js:36:46)
at Namespace.addJSON (/usr/src/app/node_modules/protobufjs/src/namespace.js:182:39)
at fromJSON (/usr/src/app/node_modules/protobufjs/src/namespace.js:36:46)
at Root.addJSON (/usr/src/app/node_modules/protobufjs/src/namespace.js:182:39)
at Function.fromJSON (/usr/src/app/node_modules/protobufjs/src/root.js:51:17)
at new LoggingServiceV2Client (/usr/src/app/node_modules/@google-cloud/logging/build/src/v2/logging_service_v2_client.js:171:62)
at new Logging (/usr/src/app/node_modules/@google-cloud/logging/build/src/index.js:132:31)
at new LoggingBunyan (/usr/src/app/node_modules/@google-cloud/logging-bunyan/build/src/index.js:149:31)
at Object.<anonymous> (/usr/src/app/api/src/utils/queue/queue_jobs/createJob.js:20:23)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)
at Module.require (internal/modules/cjs/loader.js:961:19)
at require (internal/modules/cjs/helpers.js:92:18)
at Object.<anonymous> (/usr/src/app/api/src/utils/queue/queue_jobs/index.js:1:23)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)

Code that I am running, this is the only instance of the LoggingBunyan I am creating:

const bunyan = require('bunyan');
const { LoggingBunyan } = require('@google-cloud/logging-bunyan');

// Creates a Bunyan Cloud Logging client
const loggingBunyan = new LoggingBunyan();

// Create a Bunyan logger that streams to Cloud Logging
// Logs will be written to: "projects/YOUR_PROJECT_ID/logs/bunyan_log"
const loggerBunyan = bunyan.createLogger({
  // The JSON payload of the log as it appears in Cloud Logging
  // will contain "name": "my-service"
  name: 'local_queue_logs',
  streams: [
    // Log to the console at 'info' and above
    { stream: process.stdout, level: 'info' },
    // And log to Cloud Logging, logging at 'info' and above
    loggingBunyan.stream('info'),
  ],
});
googleapis/nodejs-logging-bunyan

Answer questions andrewgbliss

I added the middleware to my express app and that part works. However when trying to add this code into just a standalone module like in the example, into the project it gives this error. So I want to be able to log in the express app and other places in the app, like utility functions.

I would assume that running just this code only works, it's taken right from the example in this repo.

useful!

Related questions

No questions were found.
source:https://uonfu.com/
answerer
Andrew Bliss andrewgbliss https://www.andrewgbliss.com Senior full stack web developer with 15 plus years of professional experience. Current stack is React, Express, Node, and Postgres.
Github User Rank List