reactjsmongodbtailwind-css

Failed to compile module not found in React.js


I ran into this problem website when am following this video tutorial until here: https://youtu.be/nGoSP3MBV2E?list=PLIZkq64ad9C4POK0E1fhCaxlxTXwr7wSh&t=5976.

The problem seem to arised from these 2 files: error from register/route.js & models/User.js

Here's the source code of those 2 files:

register/route.js: '''

  import mongoose from "mongoose";

    import {User} from "@/models/User";;

    export async function POST(req){
    const body = await req.json();
    mongoose.connect(process.env.MONGO_URL);
    const cretedUser = await User.create(body);
    return Response.json(createdUser);
}

'''

Model/User.js:

'''

    import {model, models, Schema} from "mongoose";

    const UserSchema = new Schema({
    email:{type:String, required:true, unique: true},
    password:{
        type:String, 
        required: true, 
        validate: pass => {
        if(!pass?.length || pass.length <5 ){
            new Error('password must be at least 5 characters');
        }
    },
    },
    },{timestamps: true}); 

export const User = models?.User || model('User', UserSchema);

'''

I have tried correcting any typo as well as fixing any incorrect path but nothing worked so far, here's how my repo look like:Repo


Solution

  • This should work:

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

    Also, in jsconfig.json make sure you have the following code:

    {
      "compilerOptions": {
        "baseUrl": ".",
        "paths": {
          "@/*": ["src/*"]
        }
      }
    }