How to fix import in Node.js

Good day hope u are having a nice day and a blessed month
My issue is that after clicking ctrl+ s, to run my code and connect to MongoDB on port 5000 it showed some errors, the images below will be a guide to u
But it keeps on showing this error:

    at new NodeError (node:internal/errors:405:5)
    at finalizeResolution (node:internal/modules/esm/resolve:226:11)
    at moduleResolve (node:internal/modules/esm/resolve:838:10)
    at defaultResolve (node:internal/modules/esm/resolve:1036:11)
    at DefaultModuleLoader.resolve (node:internal/modules/esm/loader:251:12)
    at DefaultModuleLoader.getModuleJob (node:internal/modules/esm/loader:140:32)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:33)
    at link (node:internal/modules/esm/module_job:75:36) {

Node.js v20.5.0
[nodemon] app crashed - waiting for file changes before starting...

Hey @Somtochukwu_Kelvin_Akuche,

Welcome to the MongoDB Community!

Thank you for sharing the error stack trace.

I would recommend posting the code snippet as text instead of an image, as it will make it easier for the community to read and assist. :slightly_smiling_face:

However, from what I can see in the image, it looks like there is a relative path error in your import.

Here are a few things you can try to resolve this:

  • Make sure the path is correct - verify that ./user.route.js etc. exists and is exported properly.
  • Try deleting your node_modules folder and reinstalling all modules with npm install. Sometimes modules can get corrupted.
  • Add debug logging in your main index.js file to print out the loaded modules and see where it is failing.

Adding more logging and verifying that the path is correct would be my recommended first step. Please feel free to post a follow-up with the specific error text if you are still stuck.

Best regards,

Okay though I reran the yarn start and it went smoothly again so I think I solved that but for the logging something pls can u tell me how þo go about it?
Pls how will I know the path is exported properly the user/…
Though it exists user.route.js, I will still do more work on it I think Ibknow where the issues for and for the code snippets I will do that 11pm UTC and send to u

@Kushagra_Kesav below are the snipppet for all of them accordingly

import express from "express"; 
import userRoute from "./user . route. js";
import mediaRoute from "./media.route. js";
import personRoute from "./person.route. js";
import reviewRoute from "./review. route. js"; 
const router = express. Router( ); 
router .use("/user", userRoute);
router .use("/person", personRoute) ;

router .use("/reviews", reviewRoute);


Import express from "express" 
import [body) from"express-validator" 
import favoriteController from " .. /controllers/favorite. controller. js"
import userController from " .. /controllers/user. controller.js" 
import requestHandler from " .. /handlers/request. handler.js"
import userModel from " .. /models/user.model.js"

import tokenMiddleware from " .. /middlewares/token.middleware. js"
 const router = express.Router();

router .post ( 
    body ("username") 
        exists() .withMessage("username is required")

        .isLength([ min: 8 }) .withMessage("username minimum 8 characters")

        .custom(async value => { 
                 const user - await userModel.findone(( username: value });
                 if (user) return Promise.reject("username already used");


        .exists/1.withMessage("password is required")
        .isLength({ min: 8 } ) .withMessage( "password minimum 8 characters"), 
    body ("confirmPassword")

        .exists().withMessage("confirmPassword is required")

        .isLength({ min: 8 }) .withMessage("confirmPassword minimum 8 characters")

       .custom((value, { req }) -> { 
              if (value ! == req.body .password) throw new Error("confirmPassword not match"); 
              return true;

        .exists() .withMessage("displayName is required")

        .isLength({ min: 8 }) .withMessage("displayName minimum 8 characters"), 
    requestHandler . validate,
    userController .signup

router .post (

         .exists() .withMessage("username is required")

         .isLength({ min: 8 }) .withMessage("username minimum 8 characters"), 
     body ("password")

          .exists() .withMessage("password is required")

          .isLength({ min: 8 }) . withMessage("password minimum 8 characters"), 
      requestHandler .validate, 


          .exists() .withMessage("password is required")

          .isLength({ min: 8 }) . withMessage( "password minimum 8 characters"), 
     body( "newPassword")

          .exists() .withMessage("newPassword is required")

          .isLength({ min: 8 }) . withMessage("newPassword minimum 8 characters"),

          .exists() .withMessage("confirmNewPassword is required")

          .isLength({ min: 8 }) . withMessage("confirmNewPassword minimum 8 characters")   
          .custom((value, { req }) => { 
                if (value ! == req. body . newPassword) throw new Error("confirmNewPassword not match"); 
                return true;
      requestHandler . validate, 
      userController .updatePassword

router .get( 
      userController .getInfo,

router .get (

router . post ( 
          .exists() .withMessage("mediatype is required")

          .custom(type => ["movie", "tv"].includes(type)) .withMessage("mediaType invalid"), 

          .exists().withMessage("mediaId is required")

          .isLength(( min: 1 )) .withMessage("mediaId can not be empty"),
      body ( "mediaTitle")

         .exists().withMessage("mediaTitle is required"), 
      body ( "mediaPoster")
         .exists( ) .withMessage( "mediaPoster is required").
      body ( "mediaRate")
         .exists() .withMessage("mediaRate is required"), 
router .delete(
      "/ favorites/ : favoriteId", 
      tokenMiddleware. auth, 

export default router;

There might be a little mistake maybe some wrong punctuation marks or the spacing even the brackets I used but from the photos I sent b4 should guide u, though I cross-checked b4 sending

Hi pls is there anyone that can look into thia for me @Justina_Ackah , @Comma_Pump_Sound-Dev , @Jad_Bsaibes , @John_Sewell , @Prakul_Agarwal @Qdev , @Vishnu_Satis @WONG_TUNG_TUNG , @Xinying_Hu , @Xin_Wen_Yap, pla the person that answered pr replied to my lasst comments he hasn’t replied me for up to 5 to 6 days npw, I understand he is busy I wpuld appreciate it if u guys can help me or refer me to where I can get help, and I would be open to explain to u incase u don’t understand my errors

Looks like an issue with inport only, can you post your project structure here, the folder structure, it will help in understanding the issue

As others have said looks like a reference error, either in referencing your other code or a library you depend on.

If you’ve added all dependencies, or taken some and not yet restored them from the package with npm install, I’d try commenting out vast swathes of your code and getting the most basic code path working and then build up until you find the error.

Or upload all your code to GIT and it would be simpler to take a peek.

You should be able to comment out everything, and get it working, then introduce one route and gradually add more etc. until you find the line that’s causing the issue.

Okay I will do that, that should be the folders section in my editor right?

The whole thing, including the root as that has the config files in it.

Be wary of any logons / passwords / server addresses and blank them out before you upload!

Okay thanks , but when u said dependencies , though I was confused of the one to add so that it won’t affect anything, later when am running the codes, though I couldn’t use npm install in the beginning bcos it kept showing lock file found and no license field so I had to reconfigure some files and added the license and remove package. Lock.json file b4 the error was removed but for that dependencies I didn’t add much just a little to my package. Json file.
I will try commenting the codes to see what’s wrong but I think it should be when I used import from a particular file that’s when the error came by, I will also upload my whole files in Github so a peek can be given

Ooh okay u mean b4 I upload to github right?

Ooh sorry to here(mongodb)

Yes, easiest is probably just copy your whole folder and then redact that copy so you don’t lose anything.

Okay will do that, thanks for your time

Pls this is the link to another post, I couldn’t post it here though bcos they said “topic has been closed by mongodb” the time I wanted to post here, my issue was the warning after running a command and I also stated what caused my issue b4 in this post I tagged u here though it was wrong import but the screenshot will explain more

@Vishnu_Satis I tagged u on a post on continuity on the post

This topic was automatically closed after 180 days. New replies are no longer allowed.