question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TS Compilation errors when using Mongo Seeding along MongoDB driver v4

See original GitHub issue

I am using mongo-seeding and mongoose in the same (typescript) project. I recently upgraded mongoose to version 6.0.4. This version of mongoose depends on mongodb 4.1.1 which does not play nicely with mongo-seeding right now.

node_modules/mongo-seeding/dist/config.d.ts:3:10 - error TS2305: Module '"mongodb"' has no exported member 'CollectionInsertManyOptions'.

3 import { CollectionInsertManyOptions, MongoClientOptions } from 'mongodb';
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/mongo-seeding/dist/database/database.d.ts:1:14 - error TS2305: Module '"mongodb"' has no exported member 'CollectionInsertManyOptions'.

1 import { Db, CollectionInsertManyOptions, MongoClient } from 'mongodb';
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/mongo-seeding/dist/database/database.d.ts:32:167 - error TS2694: Namespace 'node_modules/mongodb/mongodb"' has no exported member 'InsertWriteOpResult'.

32     insertDocumentsIntoCollection(documentsToInsert: any[], collectionName: string, collectionInsertOptions?: CollectionInsertManyOptions): Promise<import("mongodb").InsertWriteOpResult<any>>;

                         ~~~~~~~~~~~~~~~~~~~

node_modules/mongo-seeding/dist/database/database.d.ts:55:93 - error TS2694: Namespace '"node_modules/mongodb/mongodb"' has no exported member 'DeleteWriteOpResultObject'.

55     removeAllDocumentsIfCollectionExists(collectionName: string): Promise<import("mongodb").DeleteWriteOpResultObject | undefined>;
                                                                                               ~~~~~~~~~~~~~~~~~~~~~~~~~

Do you plan to upgrade mongodb (type) dependencies in the foreseeable future?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
qqilihqcommented, Dec 13, 2021

@pkosiec D’oh, sorry, you’re right.

(1) Yes, we have the recent "mongodb": "4.2.1" as a dependency. (2) But I just noticed that we still had "@types/mongodb": "4.0.7" (3) After dropping the @types/mongodb, as expected, I’ll end up with:

node_modules/mongo-seeding/dist/config.d.ts:3:10 - error TS2305: Module '"mongodb"' has no exported member 'CollectionInsertManyOptions'.

3 import { CollectionInsertManyOptions, MongoClientOptions } from 'mongodb';
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/mongo-seeding/dist/database/database.d.ts:1:14 - error TS2305: Module '"mongodb"' has no exported member 'CollectionInsertManyOptions'.

1 import { Db, CollectionInsertManyOptions, MongoClient } from 'mongodb';
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/mongo-seeding/dist/database/database.d.ts:32:167 - error TS2694: Namespace '"/Users/pk/Repositories/pagefate/api/node_modules/mongodb/mongodb"' has no exported member 'InsertWriteOpResult'.

32     insertDocumentsIntoCollection(documentsToInsert: any[], collectionName: string, collectionInsertOptions?: CollectionInsertManyOptions): Promise<import("mongodb").InsertWriteOpResult<any>>;
                                                                                                                                                                         ~~~~~~~~~~~~~~~~~~~

node_modules/mongo-seeding/dist/database/database.d.ts:55:93 - error TS2694: Namespace '"/Users/pk/Repositories/pagefate/api/node_modules/mongodb/mongodb"' has no exported member 'DeleteWriteOpResultObject'.

55     removeAllDocumentsIfCollectionExists(collectionName: string): Promise<import("mongodb").DeleteWriteOpResultObject | undefined>;
                                                                                               ~~~~~~~~~~~~~~~~~~~~~~~~~


Found 4 errors.

Guess, I’ll just keep the @types for now 😃

1reaction
pkosieccommented, Dec 13, 2021

@qqilihq I’m glad to hear that! 🙂

Just out of curiosity: do you also use the new MongoDB Node.js driver v4 (which has brand-new built-in TS types) as dependency in your app, similarly as @aleneum? I guess not, and that would explain that you didn’t need to touch the tsconfig.json file 🤔

Read more comments on GitHub >

github_iconTop Results From Across the Web

compile errors with v4.4.x under typescript 3.9.x and node 14
Unable to build a package depending on mongodb 4.4.x using ts 3.9. Notice a huge number of errors in node_modules/mongodb/mongodb.ts34.d.ts ...
Read more >
Nodejs Driver v4.4.1 doesn't handle errors correctly - MongoDB
When I run commands on a collection and the db is closed the error isn't returned in the callback but the function call...
Read more >
Error Importing "mongodb" with typescript - Stack Overflow
I'm encountering the same issue, though using Mongoose, which depends on MongoDB's native Node driver. The solution I came to was downgrading ...
Read more >
Latest version of @types/mongodb breaks tsc build #38865
I've just tested typescript@3.6.3 with @types/mongodb@3.3.6 and there are no type errors on my end. Steps I took: mkdir mongotest cd mongotest ......
Read more >
mongodb | Yarn - Package Manager
The official MongoDB driver for Node.js. Upgrading to version 4? ... NODE-4691: interrupt in-flight operations on heartbeat failure (#3457 (e641bd4) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found