Open Md-Mudassir opened 4 years ago
throw new _mongoose.Error.OverwriteModelError(name); ^ OverwriteModelError: Cannot overwrite
User
model once compiled.
On Windows, if we try to open a User.js or user.js file, both will point to the same location (which is what happened here). However, nodejs manages the modules themselves in a case-sensitive manner. So if we do: require ('./ User') and require ('./ User'), nodejs will try to register 2x. What duplicates User schema registration in mongoose.
On Linux / Mac this would not happen, because well before this error popped up, the node would scream saying that the module User.js does not exist. And it would be much simpler to find the error.
//Fix
under /Models folder .. rename User.js => UserDetails.js
for more info refer here: https://www.devpleno.com/corrigindo-o-erro-cannot-overwrite-model-model-once-compiled-no-mongoose/
File name is case sensitive . 1) In "config/passport.js" file. Go to line 6 "const User = require('../models/user');" change it to "const User = require('../models/User');"
2) In "routes/users.js" change line 6 to "const User = require('../models/User');"
Thanks Sir for the solution..
throw new _mongoose.Error.OverwriteModelError(name); ^ OverwriteModelError: Cannot overwrite
User
model once compiled.