Search code examples
nestjs

An issue with Nestjs mongoose module after installation


I installed @nestjs/mongoose with following npm command:

npm i --save @nestjs/mongoose mongoose

But when I try to lauch the app, I get following errors:

node_modules/@nestjs/mongoose/dist/decorators/prop.decorator.d.ts:2:44 - error TS2694: Namespace '"mongoose"' has no exported member 'SchemaTypeOpts'.

export declare type PropOptions = mongoose.SchemaTypeOpts<any> | mongoose.Schema | mongoose.SchemaType;
                                         ~~~~~~~~~~~~~~
node_modules/@nestjs/mongoose/dist/factories/schema.factory.d.ts:4:60 - error TS2315: Type 'Schema' is not generic.

static createForClass<T = any>(target: Type<unknown>): mongoose.Schema<T>;
                                                         ~~~~~~~~~~~~~~~~~~
node_modules/@nestjs/mongoose/dist/interfaces/mongoose-options.interface.d.ts:3:10 - error TS2305: Module '"mongoose"' has no exported member 'ConnectionOptions'.

import { ConnectionOptions } from 'mongoose';
       ~~~~~~~~~~~~~~~~~

Found 3 error(s).

Any help would be highly appreciated.


Solution

  • Revert your mongoose install down to 5.10.x. The latest version of mongoose came out with their own set of types, which ended up breaking a lot of things: Reference Issue