Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
JulesLecuir opened this issue Jun 24, 2022 · 2 comments
Open

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

JulesLecuir opened this issue Jun 24, 2022 · 2 comments
Assignees

Comments

@JulesLecuir
Copy link

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 !

@JulesLecuir
Copy link
Author

More info if you wanna reproduce the bug in the very same conditions as me:

The Git branch on my project where I try to add mongoose-history-diff: https://gitlab.com/alternatiba/noe/-/tree/mongoose-history-diff
The failing commit: https://gitlab.com/alternatiba/noe/-/commit/a630b0df9f1439d12bcbd83de8ae8cb814ae30f2

@borodayev
Copy link
Owner

Hello, @JulesLecuir. Thanks for opening the issue, I will look at this asap.

@borodayev borodayev self-assigned this Jun 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants