Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Cannot find package "mongodb-extjson" #256

Open
nixrajput opened this issue Nov 6, 2023 · 2 comments
Open

[Bug]: Cannot find package "mongodb-extjson" #256

nixrajput opened this issue Nov 6, 2023 · 2 comments

Comments

@nixrajput
Copy link

🔎 Search Terms

mongodb-winston,typescript

The problem

"winston": "^3.11.0",
"winston-daily-rotate-file": "^4.7.1",
"winston-mongodb": "^5.1.1"

Getting below error when using with TypeScript:

Cannot find package "mongodb-extjson" from "/home/user/Workspace/nodejs-projects/express-api/node_modules/winston-mongodb/node_modules/mongodb/lib/core/utils.js"

What version of Winston presents the issue?

v3.11.0

What version of Node are you using?

v20.x

If this worked in a previous version of Winston, which was it?

No response

Minimum Working Example

import {
  MongoDBTransportInstance,
  MongoDBConnectionOptions,
} from "winston-mongodb";
import { createLogger, format, transports } from "winston";

const {
  MongoDB,
}: { MongoDB: MongoDBTransportInstance } = require("winston-mongodb");

const mongoTransport = new MongoDB({
  db: LocalConfig.getConfig().MONGO_URI!,
  dbName: LocalConfig.getConfig().DB_NAME!,
  storeHost: true,
  collection: "logs",
  options: {
    useNewUrlParser: true,
    useCreateIndex: true,
    useUnifiedTopology: true,
  },
  format: format.combine(
    format.timestamp(),
    format.json()
    // errorStackFormat(),
    // format.printf(({ timestamp, level, message }) => {
    //   return `[${timestamp}] ${level}: ${message}`;
    // })
  ),
} as MongoDBConnectionOptions);

Additional information

No response

@dror-g
Copy link

dror-g commented Sep 15, 2024

Same. you can edit the file /node_modules/winston-mongodb/node_modules/mongodb/lib/core/utils.js, and comment out the section that checks if the native module is available:

  let EJSON = requireOptional('mongodb-extjson');
//  if (!EJSON) {
//    EJSON = {
//      parse: noEJSONError,
//     deserialize: noEJSONError,
//      serialize: noEJSONError,
//      stringify: noEJSONError,
//      setBSONModule: noEJSONError,
//      BSON: noEJSONError
//    };
//  }

  return EJSON;
}

This seemed to work for me. I think the reason is the mongodb package used by Winston is very outdated, as well as the require-optional module that gets this test wrong.

@dror-g
Copy link

dror-g commented Sep 15, 2024

Or, maybe better as no code change in node_modules required -
Add these lines to your package.json dependencies section:

"dependencies": {
    ...
    "mongodb-extjson": "npm:noop2",
    "snappy": "^7.1.1",
    "bson-ext": "npm:noop2" 
    }

worked for me, no issues (yet..)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants