Skip to content

TypeError: value.options.type.forEach is not a function #54

@JulesLecuir

Description

@JulesLecuir

Hi, I am trying to add this plugin to my app, as it looks amazing, but I can't get to make the plugin work in my Mongoose backend. During compilation, here's the error I get:

/home/node/app/node_modules/mongoose-history-diff/lib/utils.js:43
            value.options.type.forEach(function (obj) {
                               ^

TypeError: value.options.type.forEach is not a function
    at /home/node/app/node_modules/mongoose-history-diff/lib/utils.js:43:32
    at Array.forEach (<anonymous>)
    at Object.exports.getExcludedFields (/home/node/app/node_modules/mongoose-history-diff/lib/utils.js:34:33)
    at plugin (/home/node/app/node_modules/mongoose-history-diff/lib/index.js:50:45)
    at Schema.plugin (/home/node/app/node_modules/mongoose/lib/schema.js:1454:3)
    at Object.<anonymous> (/home/node/app/build/entities/places.js:19:13)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:14)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:92:18)
    at Object.<anonymous> (/home/node/app/build/controllers/project.js:11:18)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)

A sample file that is not working for me and producing the error above:

import {Schema, model, SchemaTypes} from "mongoose";
import DiffPlugin from "mongoose-history-diff";

const PlaceSchema = new Schema(
  {
    name: {type: String, required: true},
    summary: String,
    notes: SchemaTypes.Array,
    maxNumberOfParticipants: Number,
    deletedAt: Date,
    importedId: String,
  },
  {timestamps: true}
);

PlaceSchema.plugin(DiffPlugin as any);

export const Place = model("Place", PlaceSchema);

I am using Typescript ES2020, mongoose "^5.13.2" and mongoose-history-diff "^1.0.6".

Thanks for your help !

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions