Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

An issue with Nestjs mongoose module after installation

Tags:

nestjs

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.

like image 396
Umid Boltabaev Avatar asked Dec 02 '20 15:12

Umid Boltabaev


2 Answers

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

like image 75
Jay McDoniel Avatar answered Oct 09 '22 01:10

Jay McDoniel


The best combination that worked for me is the following.

"@nestjs/mongoose": "^7.0.4",
"mongoose": "^5.10.19",
"@types/mongoose": "^5.10.3", //dev-dependency

As of 19 Dec 2020, any version later than that did NOT work for me.

like image 36
Nechar Joshi Avatar answered Oct 08 '22 23:10

Nechar Joshi