Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

1

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;
                  ~~~~~~~~~~~



like image 307
ali rana Avatar asked Dec 18 '20 07:12

ali rana


3 Answers

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

like image 94
Phil Loctaux Avatar answered Oct 08 '22 15:10

Phil Loctaux


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.

like image 20
Maxdola Avatar answered Oct 08 '22 15:10

Maxdola


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

like image 1
ali rana Avatar answered Oct 08 '22 16:10

ali rana