Express: The requested module does not provide an export named 'User' Express: The requested module does not provide an export named 'User' mongoose mongoose

Express: The requested module does not provide an export named 'User'


You are mixing ES6 modules (import, export) with CommonJS (require/module.exports). We are going to need to replace module.exports = { User }; with export const User = mongoose.model('user', userSchema); in order to succesfully import it as an ES6 module in your other file. You can create a named export in your model file as follows:

import mongoose, { Schema } from 'mongoose';const userSchema = new Schema({  name: String,  email: String,  password: String,  type: String,  createdOn: String,  updatedOn: String});export const User = mongoose.model('user', userSchema);

Which will then allow you to import like this:

import { User } from '../models/User';