Skip to content

winston-transport this.once in the code causes app to crash. #212

@bobj82

Description

@bobj82

Please tell us about your environment:

  • winston version?
    • winston@2
    • winston@3

./package.json

"dependencies": {
"comment":"irrelevant entries removed",
      "winston": "^3.3.3",
      "winston-mongodb": "^5.0.7",
      "winston-syslog": "^2.4.4"
   },
  • _node -v outputs:_v16.13.0
  • Operating System? macOS
  • _Language? ES6/7

What is the problem?

I installed and configured winston-mongodb. When I tried to run the app, it crashed. Below are the details. I tried to fix it myself on the local copy, but it contiues to fail. So, I'm sending an issue instead of generating a pull request.

What do you expect to happen instead?

The app to start and send logs to mongodb.

Error message

 node .
/Users/bob/git/CPESN/Sandbox/passport_workspace/node_modules/winston-transport/index.js:32
  this.once('pipe', logger => {
       ^

TypeError: this.once is not a function
    at Object.TransportStream (/Users/bob/git/CPESN/Sandbox/passport_workspace/node_modules/winston-transport/index.js:32:8)
    at Object.exports.MongoDB (/Users/bob/git/CPESN/Sandbox/passport_workspace/node_modules/winston-mongodb/lib/winston-mongodb.js:56:13)
    at Object.<anonymous> (/Users/bob/git/CPESN/Sandbox/passport_workspace/logger.js:132:16)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Users/bob/git/CPESN/Sandbox/passport_workspace/server.js:9:16)

Possible Solution:

I checked the core winston code. It includes a dependency for 'one-time'. So, I tried inserting it into my copy of winston-transport/index.js in the hopes of simply using a pull request. But, I apparently did it wrong because the code still fails. I'm willing to do the pull request if you tell me how to get it working.

Changes I Tried

winston-transport/package.json
"dependencies": {
                "one-time": "^1.0.0",
                "readable-stream": "^2.3.7",
                "triple-beam": "^1.2.0"
        },
winston-transport/index.js
const { LEVEL } = require('triple-beam');
const once = require('one-time');

Implementation Excerpts

./server.js

const logger = require('./logger.js');

./logger.js

const winston = require('winston');
const { transports, format } = winston;
require('winston-mongodb');

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions