0

Tried to run nodejs application.If i run node server.js i am getting module not found error.All files path is correct but i am getting module not found error.How to resolve this issue?

I have shared the errors below with folder structure:

Folder structure:

test = Main folder
 node_modules
 src
      -controllers  =folder
      -dataaccess  =folder 
      -routes  =folder 
      -service  =folder 
      -server.js

 .angulardoc.json
 package.json
 package-lock.json
 tsconfig.json
 tslint.json

Error:

  internal/modules/cjs/loader.js:969
    throw err;
    ^

    Error: Cannot find module './dataaccess/middlewares/base/MiddlewaresBase'
    Require stack:
- C:\xampp\htdocs\test\src\server.js
←[90m    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:966
:17)←[39m
←[90m    at Function.Module._load (internal/modules/cjs/loader.js:859:27)←[39m
←[90m    at Module.require (internal/modules/cjs/loader.js:1028:19)←[39m
←[90m    at require (internal/modules/cjs/helpers.js:72:18)←[39m
    at Object.<anonymous> (C:\xampp\htdocs\test\src\server.js
:4:19)
←[90m    at Module._compile (internal/modules/cjs/loader.js:1139:30)←[39m
←[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1159:1
0)←[39m
←[90m    at Module.load (internal/modules/cjs/loader.js:988:32)←[39m
←[90m    at Function.Module._load (internal/modules/cjs/loader.js:896:14)←[39m
←[90m    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_ma
in.js:71:12)←[39m {
  code: ←[32m'MODULE_NOT_FOUND'←[39m,
  requireStack: [ ←[32m'C:\\xampp\\htdocs\\test\\serve
r.js'←[39m ]
}
Nila Vaani
  • 203
  • 1
  • 8
  • 27
  • Is there more to the error you could share? – T. Short Jan 08 '20 at 08:56
  • @T.Short::: Error posted..check it – Nila Vaani Jan 08 '20 at 09:02
  • @Nila Vaani Your path `./dataaccess/middlewares/base/MiddlewaresBase` is wrong. please check whether you have `dataaccess` folder in your project directory – Subburaj Jan 08 '20 at 09:05
  • Can you share your directory structure? Looks like from your server.js, the path "./dataaccess/middlewares/base/MiddlewaresBase" doesn't refer to actual file @NilaVaani – jerry Jan 08 '20 at 09:32
  • @jerry : I have added folder structure in my question..check it – Nila Vaani Jan 08 '20 at 09:57
  • Make sure the `src/dataaccess/middlewares/base/MiddlewaresBase.ts` is transpiled to `JavaScript` – jwchang Jan 08 '20 at 10:01
  • @InspiredJW:Can you explain clearly? with edited code – Nila Vaani Jan 08 '20 at 10:06
  • In your `tsconfig.json` try to add `"include": ["src/**/*"]` – Mickael B. Jan 08 '20 at 10:08
  • @NilaVaani I clearly see that you are trying to run your `server.js`, which is a JavaScript file. With that `server.js`, you are trying to import `src/dataaccess/middlewares/base/MiddlewaresBase.js`. I checked your github repo and found the `MiddlewaresBase.ts`. So just to make sure that the file have transpiled JavaScript version for importing from the JavaScript file. – jwchang Jan 08 '20 at 10:10
  • @InspiredJW:So how to convert that files to js?I am new in nodejs so help me – Nila Vaani Jan 08 '20 at 10:12
  • @InspiredJW : How to runt his nodejs application? What i want to do? – Nila Vaani Jan 08 '20 at 10:37
  • did you try running `node src/server.js` your server file is inside src directory – C.Gochev Jan 08 '20 at 13:39

0 Answers0