ENOENT, no such file or directory

255,017

Solution 1

Tilde expansion is a shell thing. Write the proper pathname (probably /home/yourusername/Desktop/etcetcetc) or use
process.env.HOME + '/Desktop/blahblahblah'

Solution 2

I believe the previous answer is the correct answer to this problem but I was getting this error when I tried installing npm package (see below) :

enter image description here

The fix for me was : npm init --yes

enter image description here

Solution 3

  1. First try npm install ,if the issue is not yet fixed try the following one after the other.
  2. npm cache clean ,then
  3. npm install -g npm,then npm install,Finally
  4. ng serve --o to run the project. Hope this will help....

Solution 4

I was also plagued by this error, and after trying all the other answers, magically found the following solution:

Delete package-lock.json and the node_modules folder, then run npm install again.

If that doesn't work, try running these in order:

npm install
npm cache clean --force
npm install -g npm
npm install

(taken from @Thisuri's answer and @Mathias Falci's comment respectively)

and then re-deleting the above files and re-running npm install.

Worked for me!

Solution 5

__dirname 

Gives you the current node application's rooth directory.

In your case, you'd use

__dirname + '/Desktop/MyApp/newversion/partials/navigation.jade';

See this answer:

App base path from a module in NodeJS

Share:
255,017
Kinnard Hockenhull
Author by

Kinnard Hockenhull

Updated on July 05, 2022

Comments

  • Kinnard Hockenhull
    Kinnard Hockenhull 6 months

    I'm getting this error from my node app:

    ENOENT, no such file or directory '~/Desktop/MyApp/newversion/partials/navigation.jade'
    

    I know the file is there because when I try to open the file using the exact copied and pasted path, it works. I also know the application is using the right directory because, well, it outputs it in the error.

  • Kinnard Hockenhull
    Kinnard Hockenhull almost 9 years
    Hmm, I thought that was handled by app.locals.basedir = '~/Desktop/BitBox/thenewbox'; I tried app.set('home', process.env.HOME || '/Users/Kinnard/Desktop/BitBox/thenewbox'); But that didn't work, same error.
  • Kinnard Hockenhull
    Kinnard Hockenhull almost 9 years
    Ok, just changing app.locals.basedir = '~/Desktop/BitBox/thenewbox'; to the absolute path worked. Thanks!
  • pnet
    pnet over 4 years
    I'm having this error too. I have no path: ..node_module/rxjs. What am i doing wrong? my issue: ** ./node_modules/rxjs/_esm5/index.js Module build failed: Error: ENOENT: no such file or directory, open '..\ClientApp\node_modules\rxjs_esm5\index.js'**
  • BraveNewMath
    BraveNewMath about 4 years
    You might want to look at this answer: stackoverflow.com/questions/21637099/…
  • ruffin
    ruffin over 2 years
    Can you explain what this does and why it might fix the issue?
  • Prusio
    Prusio almost 2 years
    what does npm install -g npm do? any doc i can find info about it?
  • Damien
    Damien over 1 year
    @Prusio It is the command to update npm (after it has been installed).
  • Manoj
    Manoj 10 months
    Yes this magic way of solution helped me.