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

NodeJS 20 Deprecation Warning DEP0170 #218

Open
samuelexferri opened this issue May 15, 2023 · 10 comments
Open

NodeJS 20 Deprecation Warning DEP0170 #218

samuelexferri opened this issue May 15, 2023 · 10 comments
Assignees

Comments

@samuelexferri
Copy link

I'm using NodeJS 20 and this Winston MongoDB config:

const logger: CustomLevels = winston.createLogger({
    ...winstonLoggerOptions,
    transports: [
        new MongoDB({
            level: "info",
            db: dbURL,
            options: {
                serverSelectionTimeoutMS: 2147483647, // Never stop trying to reconnect
                useNewUrlParser: true,
                useUnifiedTopology: true,
            },
            collection: "logs",
            storeHost: true,
            capped: false, // Alternative to expireAfterSeconds
            tryReconnect: true,
            decolorize: true,
            expireAfterSeconds: 60 * 60 * 24 * 120, // 120 days
        }),
        new winston.transports.Console({
            level: "debug",
        }),
    ],
});

I get this warning when running:
(node:40350) [DEP0170] DeprecationWarning: The URL mongodb://project-staging:password@sp-cluster0-shard-00-02.t3lku.gcp.mongodb.net:27017,sp-cluster0-shard-00-00.t3lku.gcp.mongodb.net:27017,sp-cluster0-shard-00-01.t3lku.gcp.mongodb.net:27017/project-staging?authSource=admin&replicaSet=sp-cluster0-shard-0&ssl=true is invalid. Future versions of Node.js will throw an error.

Earlier versions of NodeJS (<19) don't throw any warnings.

@DABH
Copy link
Contributor

DABH commented Jul 10, 2023

Open to PRs that would help address/fix this issue, if you're up for investigating a bit further as to why we're getting this error. Unsure if we need to change the URL being generated, or if we can do things differently with Node so that it doesn't complain about this URL type.

@DABH
Copy link
Contributor

DABH commented Jul 13, 2023

It's possible this is related to our need to do a major version upgrade of the mongodb package, see #223 which is currently failing. If you (or anyone else) would like to volunteer to help get that working, it would be a fantastic help and would help continue the useful life of this transport.

@usaszerelem
Copy link

usaszerelem commented Jul 26, 2023

Confirming that this is happening with increased frequency. Had this confirmed with Atlas DB support. Node version 20, all the latest NPM packages as of this writing. Below output with --trace-deprecation flag turned on.

(node:30480) [DEP0170] DeprecationWarning: The URL mongodb://user:password@ac-mrbfemw-shard-00-00.xpoqxtm.mongodb.net:27017,ac-mrbfemw-shard-00-01.xpoqxtm.mongodb.net:27017,ac-mrbfemw-shard-00-02.xpoqxtm.mongodb.net:27017/?authSource=admin&replicaSet=atlas-cu6uf5-shard-0&retryWrites=true&w=majority&ssl=true is invalid. Future versions of Node.js will throw an error.
at getHostname (node:url:544:17)
at Url.parse (node:url:409:14)
at Object.urlParse [as parse] (node:url:166:13)
at parseConnectionString (/Users/user/Projects/Node/products-api/node_modules/winston-mongodb/node_modules/mongodb/lib/core/uri_parser.js:578:9)
at QueryReqWrap.callback (/Users/user/Projects/Node/products-api/node_modules/winston-mongodb/node_modules/mongodb/lib/core/uri_parser.js:127:7)
at QueryReqWrap.onresolve [as oncomplete] (node:internal/dns/callback_resolver:49:10)

From Atlas DB engineers:
The warning is coming from winston-mongodb which has a dependency on mongodb: ^3.6.2.
The 3.x driver did make use of the deprecated API

@DABH
Copy link
Contributor

DABH commented Jul 26, 2023

Yeah, so like I mentioned above, I think we need someone from the community to help us get #223 working. If anyone can make that PR pass the tests, it will fix this issue for everyone going forwards. Let me know if anyone is willing to take this on - it would obviously be a huge help and greatly appreciated!

@usaszerelem
Copy link

Hello David, thank you for your response. I am a relatively beginner with Node, so I know enough to be dangerous but not sufficiently to help in the requested capacity. What I commit to do is that if somebody steps up to help, I will provide funding for this project.

@DABH
Copy link
Contributor

DABH commented Jul 27, 2023

Sponsorship would enable me to take a stab at this! :) https://github.com/sponsors/DABH But very open in the meantime if someone in the community wants to volunteer.

@Sakibdevlekar
Copy link

i like to give it a try to solve this issue, can you assign this task to me

@DABH
Copy link
Contributor

DABH commented Mar 2, 2024

Absolutely! Thanks @Sakibdevlekar for volunteering to investigate. If you happen to reproduce and fix this issue, please feel free to tag me for review in a PR! 🙏

@Neitan2001
Copy link

Hello, I am facing the same issues. Is this issue resolved?

@MattMinerQuotable
Copy link

Hi all, not sure if this is still on people's minds, but here is a good question / answer on Stackoverflow dealing with a similar issue:
https://stackoverflow.com/questions/76594556/receive-dep0170-when-connecting-mongodb-atlas-with-node-js-20-3-1

Essentially, looking at the node docs on this one (https://nodejs.org/api/deprecations.html#DEP0170), it looks as if this is based on an issue with the current mongodb implementation (as mentioned above with the bump to mongodb 6.5.0). @Sakibdevlekar were you able to resolve this?

Sakibdevlekar added a commit to Sakibdevlekar/winston-mongodb that referenced this issue May 10, 2024
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

6 participants