mongoose-aggregate-paginate-v2
mongoose-aggregate-paginate-v2 copied to clipboard
throw new Error('First param to `schema.plugin()` must be a function
When I import this package like this:
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import aggregatePaginate from 'mongoose-aggregate-paginate-v2';
@Schema({
timestamps: true,
})
export class User {
@Prop({ required: true, unique: true })
email: string;
@Prop({ required: true })
password: string;
}
export const UserSchema = SchemaFactory.createForClass(User);
UserSchema.plugin(aggregatePaginate);
I got this error:

But when I change import like this:
// eslint-disable-next-line @typescript-eslint/no-var-requires
const aggregatePaginate = require('mongoose-aggregate-paginate-v2');
error solved.
What's the problem?
this is my tsconfig:
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": false,
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false
}
}
@mortezasabihi Sorry the TS version is not managed in this repository.
@mortezasabihi This works for me:
import * as aggregatePaginate from 'mongoose-aggregate-paginate-v2';