700 viewsMern Amazona

Error [ERR_MODULE_NOT_FOUND]: Cannot find module ‘C:\Users\minal\Desktop\ecommstore\backend\models\userModel.js’ imported from C:\Users\minal\Desktop\ecommstore\backend\routes\seedRoutes.js

I am getting this error

import mongoose from ‘mongoose’;

const userSchema = new mongoose.Schema(
name: { type: String, required: true },
email: { type: String, required: true, unique: true },
password: { type: String, required: true },
isAdmin: { type: Boolean, default: false, required: true },
timestamps: true,

const User = mongoose.model(‘User’, userSchema);
export default User;

import express from ‘express’;
import Product from ‘../models/productModel.js’;
import data from ‘../data.js’;
import User from ‘../models/userModel.js’;

const seedRouter = express.Router();

seedRouter.get(‘/’, async (req, res) => {
await Product.remove({});
const createdProducts = await Product.insertMany(data.products);
await User.remove({});
const createdUsers = await User.insertMany(data.users);
res.send({ createdProducts, createdUsers });
export default seedRouter;

Bassir Answered question October 13, 2022

the error is clear. make sure you have access to userModel.js in seedRoutes.js

use control+click in vs code on import userModel to see if it open the userModel.js or not.

Bassir Answered question October 13, 2022