Reputation: 769
I have the following Schema for a User:
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
// Create Schema
const UserSchema = new Schema({
username: {
type: String,
unique: true,
default: ""
},
email: {
type: String,
required: true
},
date: {
type: Date,
default: Date.now()
}
});
module.exports = User = mongoose.model("users", UserSchema);
For some annoying reason, I am getting [eslint] User is not defined
error. What's wrong here?
I am using MERN stack webpack.
Upvotes: 0
Views: 200
Reputation: 1348
You should define User object first and then export it like as bellow
var User = mongoose.model("users", UserSchema);
module.exports = User;
Upvotes: 2
Reputation: 769
Solved it by adding:
/*globals User:true*/
at the top of the file. This dealt with Eslint solving no-undef
and then no-native-reassign
error.
Upvotes: 0