javascriptnode.jsfilemodularization

Hello, On a node.js project, and I cannot move files to a src folder because I got an error when running the node file. Now the files are in the root


Error: Cannot find module '/Users/alejandraola/Documents/GitHub/SCL16-md-link/prueba.js' at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15) at Function.Module._load (node:internal/modules/cjs/loader:769:27) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12) at node:internal/main/run_main_module:17:47 { code: 'MODULE_NOT_FOUND', requireStack: [] }

I expected to be able to. move the files to an src folder and run the files from there.


Solution

  • The error means that node cannot find the module any more after it moved

    I think you are importing these files somewhere inside your code,

    you need to find this and change it to the new directory,

    it will be something similar to this :

    require("/prueba.js");
    

    If you moved it to Src folder then add this to the path as well

    require("/src/prueba.js");