Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

286
Views
nodejs cannot find local module

I'm trying to implement a local library (made for me) but when I try to execute the code the console throws this error:

PS C:\Users\dydie\Documents\Proyecto Sena> node src/index.js
node:internal/modules/cjs/loader:942
  throw err;
  ^

Error: Cannot find module './back js/algorithms.js'
Require stack:
- C:\Users\dydie\Documents\Proyecto Sena\src\back js\utilities.js
- C:\Users\dydie\Documents\Proyecto Sena\src\index.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:939:15)
    at Module._load (node:internal/modules/cjs/loader:780:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\dydie\Documents\Proyecto Sena\src\back js\utilities.js:4:19)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Module._load (node:internal/modules/cjs/loader:827:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\Users\\dydie\\Documents\\Proyecto Sena\\src\\back js\\utilities.js',
    'C:\\Users\\dydie\\Documents\\Proyecto Sena\\src\\index.js'
  ]
}

Node.js v18.0.0

seems that the error comes from this line:

const utilities = require("./back js/utilities.js");

ironically I before used the same code for other file and it was working (and still working)

what can I do? I tried to delete and install node_modules and it didn't work.

any idea? thanks for your atention

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If back js/utilities.js wants to require algorithms.js and it's in the same folder as utilities.js, then it should require('./algorithms.js'), not require('./back js/algorithms.js') Because the path for a require is relative to the file that is executing the require command.

~/index.js would need require('./back js/algorithms.js') to directly require ~/back js/algorithms.js but ~/back js/utilities.js would only need require('./algorithms.js') to require ~/back js/algorithms.js

Note that if ~/back js/utilities.js wrote require('./back js/algorithms.js') then it would be looking for ~/back js/back js/utilities.js...which is likely not the intended path.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!