'Error TS6200 & Error TS2403: Definitions of the following identifiers conflict with those in another file

I'm trying to set up a node project in typescript.

Two files causing errors :

  1. node_modules@types\mongoose\index.d.ts
  2. node_modules\mongoose\index.d.ts

[errors][1] [1]: https://i.stack.imgur.com/46vDU.jpg

node_modules/@types/mongoose/index.d.ts:79:1 - error TS6200: Definitions of the following identifiers conflict with those in another file: DocumentDefinition, FilterQuery, UpdateQuery, NativeError, Mongoose, CastError, ConnectionOptions, Collection, Connection, disconnected, connected, connecting, disconnecting, uninitialized, Error, QueryCursor, VirtualType, Schema, SchemaTypeOpts, Subdocument, Array, DocumentArray, Buffer, ObjectIdConstructor, Decimal128, Map, Aggregate, SchemaType, Document, ModelUpdateOptions

79 declare module "mongoose" {


node_modules/mongoose/index.d.ts:1:1
 1 declare module "mongoose" {
   ~~~~~~~
 Conflicts are in this file.

node_modules/@types/mongoose/index.d.ts:226:14 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'SchemaTypes' must be of type 'typeof Types', but here has type 'typeof Types'.

226   export var SchemaTypes: typeof Schema.Types;
                  ~~~~~~~~~~~





Solution 1:[1]

Mongoose includes TypeScript types since [email protected], so you can remove the package @types/mongoose.

Source: https://developer.mongodb.com/community/forums/t/schema-error-while-running-backend-server-nestjs-angular/12440/3

Solution 2:[2]

I just had the same issue and fixed it by adding "skipLibCheck": true to my tsconfig.json. So I didn't have to downgrade Mongoose.

Solution 3:[3]

nevermind I downgraded mongoose by running 'npm i [email protected]', it worked

Solution 4:[4]

If someone is still looking for a solution and the points above did not help, uninstalling @types/mongoose-unique-validator solved my build errors.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Phil Loctaux
Solution 2 Maxdola
Solution 3 ali rana
Solution 4 Mamo