mongoose-aggregate-paginate-v2 icon indicating copy to clipboard operation
mongoose-aggregate-paginate-v2 copied to clipboard

throw new Error('First param to `schema.plugin()` must be a function

Open mortezasabihi opened this issue 3 years ago • 2 comments

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: image

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 avatar Jan 10 '22 11:01 mortezasabihi

@mortezasabihi Sorry the TS version is not managed in this repository.

aravindnc avatar Mar 03 '22 14:03 aravindnc

@mortezasabihi This works for me:

import * as aggregatePaginate from 'mongoose-aggregate-paginate-v2';

ihar-bachkouski avatar Jul 22 '22 07:07 ihar-bachkouski